????? ????? SQL ??? ????? ??????? ???????? .NET ???? .NET ODBC ??? Visual C#

?????? ????????? ?????? ?????????
???? ???????: 310130 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

??? ???? ????? ???? ????? ??????? ????? SQL Server ??????? ??? ?????? ???????? ???? ????? .NET ODBC ? Visual C# .NET.

????? ??? ????? ????? ???? ?? ?????? ???????? ???? .NET ODBC ?????? ?????? ?? ????? ??? ??????? ???????? SQL ?? ???? OLE DB ???? ?????? ???? ???: ??? ??????? ??????? ?????? ???????? ???? ???? ODBC CALL ????? ?? ??? ????? ????. ?????? ??? ??????? ?????? ??? ???? ?????? ?????? CALL ???? ??????? "????????? ???????" ?? ?????? ????????? ODBC ?? ????? MSDN.

????? ???? ????????

  1. ????? ??? ???? ??? ???? ???? ??????? ????? ????? ????? ?? ????? ?????? ????? Northwind ????? ????? ????? ?????:
    {CALL CustOrderHist (?)}
  2. ????? ??? ???? ??? ???? ???? ??????? ????? ???? ????? ????? ????? ????? ?? ???? ????? ????? ???? "?" ???? ?????. ???? ????? ?????? ????? ???? ???????:
    {? = CALL Procedure1 (?, ?)
  3. ODBC .NET ????? ???? ? ??? ???? OLE DB, ????? ????????? ?? ???? ?????? ???????? (?????) ?? ??? ?????.

?????? Project - ????? ????? ?????

  1. ??? ?? ??? ?? ??? ?????? ?????? ??? ? ????? ?????? ?????? ??????? .NET ODBC ?? ???? Microsoft ?????? ??? ?????:
    http://msdn.microsoft.com/en-us/data/aa937729.aspx
  2. ??? ????? Visual Studio .NET ?? ?? ?????? Visual C# ".NET Windows ?????" ???? ???? ?? ???????.
  3. ?? ??????? ??????? ???? ??? ????? ???? ??? ?? ???? ????? ??????? ??? Microsoft.Data.ODBC.dll ??????? ??? ????? ??????? ???????. ????? ???? ?????? ?????.
  4. ?? ???? ?????? ?? ?????? "??????? ??????" ? ?? ?????? ???????? ???????:
    using System.Data;
    using Microsoft.Data.Odbc;
    					
  5. ?? ???? ???? ???? ?? ?? ???? ??????? ??? ??????? ?????????.
  6. ???? ????? ??????? ??? ?? ??? ??? ??????? ??? ???? ????????? ???????? ???? ???? ????. ???? ?? ?? ???? ???????? ???????? ????? ?? ????? ????? ???? ????? ????? ????? ???? SQL ???????:
    OdbcConnection cn;
    OdbcCommand cmd;
    OdbcParameter prm;
    OdbcDataReader dr;
    
    try {
        //Change the connection string to use your SQL Server.
        cn = new OdbcConnection("Driver={SQL Server};Server=servername;Database=Northwind;Trusted_Connection=Yes");
    
        //Use ODBC call syntax.
        cmd = new OdbcCommand("{call CustOrderHist (?)}", cn);
    
        prm = cmd.Parameters.Add("@CustomerID", OdbcType.Char, 5);
        prm.Value = "ALFKI";
    
        cn.Open();
    
        dr = cmd.ExecuteReader();
    
        //List each product.
        while (dr.Read()) 
    	Console.WriteLine(dr.GetString(0));
    
        //Clean up.
        dr.Close();
        cn.Close();
    }
    catch (OdbcException o) {
        MessageBox.Show(o.Message.ToString());
    }
    					
  7. ????? ???????. ??? ???????? ???????? ????????? ??????? "CustOrderHist" ????? ????? ?? ????? ?????? ?????? ????? ???? ?????? resultset. ?? "???? ???????" ???? ????? ???????? ???? ?????? Northwind ALFKI.

    ??????: ???? CTRL + ALT + O ???? "???? ???????".

?????? Project - ????? ????? ??????

  1. ???????? "???? ???????" ? ????? ????? ???? ??????? ?? ????? ?????? ????? Northwind. ???? ???? ?????? ?????? ????? ??? ??????? ?????? ?????? ??? ????? ??????? ??? ??????? ????? ????? ??????? ??? ????? ???????? ?????? ??? ?????? ???? ????? ????? ?????? ??? ??????? ???? ????? ?? ??? ??????? ????? ?????.
    CREATE PROCEDURE usp_TestParameters
    @CustID CHAR(5),
    @AvgFreight MONEY OUTPUT
    AS
    SELECT @AvgFreight = AVG(Freight) FROM Orders WHERE CustomerID = @CustID
    SELECT * FROM Orders WHERE CustomerID = @CustID
    RETURN @@ROWCOUNT
    					
  2. ??? ??????? ?? 1 ??? 6 ?????? ??????? ??????? ????????? ???????? ?? ????? ????? Click ??? ?????:
    OdbcConnection cn;
    
    try {
        cn = new OdbcConnection("Driver={SQL Server};Server=servername;Database=Northwind;Trusted_Connection=Yes");
    
        OdbcCommand cmd = new OdbcCommand("{? = call usp_TestParameters (?, ?)}", cn);
    
        OdbcParameter prm = cmd.Parameters.Add("@RETURN_VALUE", OdbcType.Int);
        prm.Direction = ParameterDirection.ReturnValue;
    
        prm = cmd.Parameters.Add("@CustomerID", OdbcType.Char, 5);
        prm.Value = "ALFKI";
    
        prm = cmd.Parameters.Add("@AvgFreight", OdbcType.Double);
        prm.Direction = ParameterDirection.Output;
    
        cn.Open();
        OdbcDataReader dr = cmd.ExecuteReader();
    
        while (dr.Read())
             Console.WriteLine(dr.GetString(0));
    
        dr.Close();
        cn.Close();
    
        Console.WriteLine("Average Freight (output param): {0}", cmd.Parameters[2].Value);
        Console.WriteLine("Order Count (return value): {0}", cmd.Parameters[0].Value);
    
    }
    
    catch (OdbcException o) {
        MessageBox.Show(o.Message.ToString());
    }
    					
  3. ????? ???????. ??? ???????? ???????? ????????? ??????? "usp_TestParameters" ????? ???? ???? ??????? ?? ?????? 1 ?????? ??????? ?? ????? ?????? ??? ????? ????? ????? ????? ?????? resultset ? ????? ????? ???? ?????. ?? ?????? "?????" ? ??? ?? ????? ????? ??????? ?????? ??????? Northwind ALFKI ????? ??????? ???????? ?????? ??? ????? ???? ???????.

    ??????: ???? CTRL + ALT + O ???? ?????? ?????.

??????? ??????? ????????

  • ?? ???? ??????? ?????? ADO ?????? ???? ??????? ????????? ??????? ??? ??? ????? ??? ????? ???? ?? CommandText ? ???????? ???? ????? .NET ODBC.
  • ????? ???? ????? ???? ??? resultset ? ??????? ????? (??????) ? ???? ??????? ??? ?????? ??? ?????? ??? resultset ?? ?????. ??? ???? ??????? ??? ???? ??? ????? "dr.Close()" ?? ??????? ?????? ????? ???? ????? ??? ???? ??? ??????? ??? ????? ??????? "?" ???? ???????.
  • ODBC .NET ????? ???? ? ??? ???? OLE DB, ????? ????????? ?? ???? ?????? ???????? (?????) ?? ??? ?????.
  • ?? ???? ?? Visual Studio .NET ?????? ??????? .NET ODBC ???? ??? ????? ???? ?????.

?????

?????? ??? ??????? ?????? ??? ???? ???? ODBC CALL ???? ??????? "????????? ???????" ?? ?????? ????????? ODBC ?? ????? MSDN.

???????

???? ???????: 310130 - ????? ??? ??????: 13/????? ??????/1425 - ??????: 3.4
????? ???
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET 1.1
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
????? ??????: 
kbmt kbdatabase kbhowtomaster kbsystemdata KB310130 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????310130

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com