????? ??????? ?????? ?????? ?? ?? ?????? ??? ???????? ADO.NET 2005 ? Visual C# 2005 ?? ???????? ADO.NET Visual C# .NET

?????? ????????? ?????? ?????????
???? ???????: 306636 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ????? ??????? ADO.NET 2005 ?? ADO.NET ??????? ?????? ?????? ?????? ???.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • ?????? Microsoft Windows NT 4.0 ?? Microsoft Windows Server 2003 Microsoft Windows 2000 Professional Windows 2000 Server Windows 2000 Server? ??????
  • Microsoft Visual Studio 2005 ?? Microsoft Visual Studio .NET
????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • ??????? ????? ????????
  • ??? ????????? ???????? (SQL)

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

??? ????? ??????? ?? ????? ???????? ??? ????? ??????? ????? ????? ???????? ???? ?? ???? ???? ????? ????? ????? ??????. ????? ??????? OleDbCommand ?? ?????? SqlCommand ?????? ??? ??? ????? ??? ???? ???????? ? ???? ?? ???? OleDbCommand ????? ????????. ???? ??? ??????? ?? ??? SqlClient (??????? ????? ??????? ???? ????? ??????? Microsoft SQL Server) ? ??? OleDb (?? ????? ?????? OLE DB ?? ODBC ?????? ????? ???) ???? ADO.NET. ??? ???? ???????? ???????? ?? ???? ??? ??? ?????.

???????? ADO, ????? ????? ????? ???? ??????? ?? ??????? ?? ???? Recordset. ?? ADO.NET ? ??????? ?????? ??? (SqlCommand ?? OleDbCommand) ????? ???????.

?????? ??? ???? ??????? ???????:
  1. ???? ??????? ??????? ?????? ????? ???? ???? ????? ?? Microsoft Visual C# 2005 ?? ?? Microsoft Visual C# .NET:
    1. ??? ????? Microsoft Visual Studio 2005 ?? Microsoft Visual Studio .NET.
    2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
    3. ?? ???? ?????? ????? ???? ? ???? ??? Visual C# ?????? ??? ????? Project ?? ???? ??? ????? ???? ?????? ??? ?????.

      ?????? ?? Visual Studio 2005 ? ???? ??? Visual C# ??? ????? Project ?? ???? ?????? ????? ???? ?? ???? ??? ????? ???? ?????? ??? ?????.
  2. ???? ?? ?? ????? ??????? ??? ???? ??? ????? ????? System.Data ?? ????? ???? ??? ?? ???.
  3. ?????? ??????? ???????? ??? ?????? ????? "????" ? "System.Data ???? ?? ???? ????? ????????? ?? ????? ??????? ?????? ?? ????????? ????????. ????? ????? ????? System.Data.SqlClient ?? System.Data.OleDb ? ???????? ??? ???? ???????.
    using System;
    using System.Data;
    using System.Data.SqlClient;
    					
  4. ??? ?? ????? ?? ????? ????? ????? ?????? ??? ?? ???? ???? ????? ?????. ????? ????? ????? ??? ???? ????????? ???? ????? ?????? ????? ????? ?????? ??? ?? ??? ??? ?????? "?" ??? ????? ???????? "?" ????? ???????? "?" ???? ??????. ??? ???? ??????? ???? ????? ??????? ??????? ??? ??????? ???? ????? ???? SQL:

    ??????? OleDb:

    ????????? ?? ???? ???? ???????? <uid>???? ???????? ???????? ?????? ??? ???????? ??? ????? ????????.
    Provider=SQLOLEDB.1;User ID=<UID>;Initial Catalog=pubs;Data Source=(local)
    						
    ????????? ?????? SqlClient:
    User ID=<UID>;Initial Catalog=pubs;Data Source=(local)
    						
    ????? ?????? ??? ????? ??? ?????? ?? ????? ??????? ????? ?????? ????? ?? "?????_?????" ??? ????? ???? ????? Microsoft (MSDN) ??:
    http://msdn.microsoft.com/en-us/default.aspx
  5. ???? Visual Studio ?????? ??? ????? ??? ????? Main() ????. ????? ????? ????? ?????? ????? ??????? ??????? ????? ???????? ?????? ?? ?? ??? ???????.

    ????????? ?? ???? ???? ???????? <uid>???? ???????? ???????? ?????? ??? ???????? ??? ????? ????????.
    class Class1
    {
    	static void Main(string[] args)
    	{
    		string sConnectionString = 
    "User ID=<UID>;Initial Catalog=pubs;Data Source=(local)";
    	}
    }
    					
  6. ???????? ??? ????? ??????? ????? ???? ???? OleDbConnection ?? SqlConnection ???????? ?? ????? ????? ????? ?????? ???????? ?????? ??:
    SqlConnection objConn = new SqlConnection(sConnectionString);
    objConn.Open();
    					
  7. ?? ?????? ???? SqlCommand ?? OleDbCommand ?? ????? ?? ????? ???? ???? ????? "?" ???? ??????? ???? ??? ??????? ?? ?????? ???????. ????? ????????? ???????? ?????? ?????? ?? ???? INSERT:
    string sSQL = "INSERT INTO Employee " + 
      "(emp_id, fname, minit, lname, job_id, job_lvl, pub_id, hire_date) " + 
      "VALUES ('MSD12923F', 'Duncan', 'W', 'Mackenzie', 10, 82,'0877','2001-01-01')";
    SqlCommand objCmd = new SqlCommand(sSQL,objConn);
    					
  8. ??? ????? ???? SqlCommand ?? OleDbCommand ???? ??????? ??????? ExecuteNonQuery ?????? ????? ???? ?????. ?? ????? ExecuteNonQuery ????? ??? ????? ??? ????? (??? ?????? INSERT ? UPDATE ?? DELETE). ??? ??? ??? ????? ??????? ??? ??? ??????? (???? ????????? ???????? ???????) ? ?? ????? ????? ????? ?? ????? ????????.
    objCmd.ExecuteNonQuery();
    					
  9. ??? ??????? ????? ??. ?? ??????? ????? ? ???? ??? "????" ?????? ????? ????? ??????.

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

??? ????? ??????? ????? ????? ?????? (??? UPDATE ? INSERT ??? DELETE ?????? ?? ????????? ????????? ???????) ? ??? ???? ????? ??? ?????? ??? ???????. ???? ??? ????? ??? ????? ??? ????? ???? ????? ??? ???? ???????? ????? ???????? ???? ??? ??????? ????? ?? ????????. ?? ???? ???????? ????? DELETE ???????? ??? ????? INSERT ????????? ?? ?????? ??????:
string sSQL = "DELETE FROM Employee WHERE emp_id = @emp_id"
				
???? ??? ??????? ("@ emp_id") ?? ??? ?????? DELETE ????? ?? ????? ??????? ??? ?????? ?? ??? ??? ???? ????? ?????.

??????? ?????? ?? ????? ? ???? ??????? ???????:
  1. ????? ???? OleDbConnection ?? SqlConnection ??? ???? ?? ??? "How to run a command".
  2. ??????? ??? ??????? ??????? (??? ???? ??????? "@ emp_id" ?? "@ fname") ???? ?????? ?? ????? ????????. ???? ???? DELETE ??? ??????? ??????? ?????? ??? ????.
  3. ????? ???? OleDbCommand ?? SqlCommand ?? ????? ?? ???? ??????? ???? ??? ??????? ?? ?????? ?????? "?" ?? ????? ???? ????? ??? ????? ????? ???????.
  4. ??? ????? ????? ???? ????? ??? ?????? ???????? ?????? ?????. ??? ????? ??? ???? ?????? ??? ?????.
    objCmd.Parameters.Add("@emp_id", SqlDbType.Char, 9);
    					
  5. ???? ?? ????????? ??????? ???????? ???? ???? ??? ?????? ????????. ??? ????? ????? ???? ?? ?? ????? ??????? ??? ?? ????? ?? ????? ?????????:
    objCmd.Parameters["@emp_id"].Value = "MSD12923F";
    					
  6. ????? ????????? ??? ???:
    try 
    {
    	objCmd.ExecuteNonQuery();
    }
    catch (System.Exception e) 
    {
    	Console.WriteLine(e.Message);
    }
    Console.WriteLine("Record Deleted");
    					

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

????????? ?? ???? ?????? "????? ????????" = <uid>??? ????? ??????? ??? ????? ??? ????????? ????????. ???? ?? ?? <uid>???? ???????? ???????? ?????? ??? ??????? ??? ????? ????????.
using System;
using System.Data;
using System.Data.SqlClient;

    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
	static void Main(string[] args)
	{
		AddRecord();
		RemoveRecord();
		Pause();
	}

	static void Pause()
	{
		Console.WriteLine("Press Enter To Continue....");
		Console.ReadLine();
	}

	static void AddRecord()
	{
		string sConnectionString = "User ID=<UID>;Initial Catalog=pubs;Data Source=(local)";
		SqlConnection objConn = new SqlConnection(sConnectionString);
		objConn.Open();
		string sSQL = "INSERT INTO Employee " + 
		  "(emp_id, fname, minit, lname, job_id, job_lvl, pub_id, hire_date) " + 
	          "VALUES ('MSD12923F', 'Duncan', 'W', 'Mackenzie', 10, 82,'0877','2001-01-01')";
		SqlCommand objCmd = new SqlCommand(sSQL,objConn);
		try 
		{
			objCmd.ExecuteNonQuery();
			}
		catch (System.Exception e) 
		{
			Console.WriteLine(e.Message);
		}
		Console.WriteLine("Record Added");
	}

	static void RemoveRecord()
	{
		string sConnectionString = "User ID=<UID>;Initial Catalog=pubs;Data Source=(local)";
		SqlConnection objConn = new SqlConnection(sConnectionString);
		objConn.Open();
		string sSQL = "DELETE FROM Employee WHERE emp_id = @emp_id";
		SqlCommand objCmd = new SqlCommand(sSQL,objConn);
		objCmd.Parameters.Add("@emp_id", SqlDbType.Char, 9);
		objCmd.Parameters["@emp_id"].Value = "MSD12923F";
		try 
		{
			objCmd.ExecuteNonQuery();
		}
		catch (System.Exception e) 
		{
			Console.WriteLine(e.Message);
		}
		Console.WriteLine("Record Deleted");
	}
} 
				

?????

?????? ??? ???? ?? ????????? ??? ????? ??????? ADO.NET ????? ????? ???????? ?????????? ??????? ?????? ????? Microsoft ??????? ??? ?????:
SQL Server 2000 ????? ???????
http://msdn2.microsoft.com/en-us/library/aa214299(SQL.80).aspx

"diving ??? Access ????????" ?????? ??????? MSDN
http://msdn2.microsoft.com/en-us/library/ms810295.aspx

ADO.NET ?? ????????? ADO
http://msdn2.microsoft.com/en-us/library/ms973217.aspx

MSDN ???? ?????? .NET Online
http://msdn.microsoft.com/net
????? ?? ?????????? ???? ?????? ??????:
??? ? ???? "?" Jon Jagger. Microsoft Visual C# .NET Step by Step. Microsoft Press 2003.
????? ?? ?????????? ???? ?????? ????????? ??????? & ??????? Microsoft ???????:
????? 2389 ???????? ADO.NET
http://www.microsoft.com/learning/syllabi/en-us/2389Bfinal.mspx

???????

???? ???????: 306636 - ????? ??? ??????: 04/?????/1428 - ??????: 4.9
????? ???
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# 2005
????? ??????: 
kbmt kbhowtomaster kbsqlclient kbsystemdata KB306636 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????306636

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

 

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