连接什么数据库?看看这些已经问过的问题。
http://expert.csdn.net/Expert/ForumList_Search.asp?searchtype=2&bigclassid=52&smallclassid=5201&searchKeys=%C1%AC%BD%D3%25%CA%FD%BE%DD%BF%E2&author=&tabletype=now
http://expert.csdn.net/Expert/ForumList_Search.asp?searchtype=2&bigclassid=52&smallclassid=5201&searchKeys=%C1%AC%BD%D3%25%CA%FD%BE%DD%BF%E2&author=&tabletype=now
<add key="DSN" value="Data Source=202.96.137.85;initial catalog=EA;uid=sa;pwd=123456"/>
</appSettings>写作Web.config
杂办???大虾 帮帮我!!急急
using System.Data;
using System.Data.SqlClient;class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories"; nwindConn.Open(); SqlDataReader myReader = catCMD.ExecuteReader(); while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
} myReader.Close();
nwindConn.Close();
}
}
using System.Data.OleDb;
---------------------------
OleDbConnection thisConnection=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\D\DevCs\Works2\Person.mdb;");
thisConnection.Open();
OleDbCommand thisCommand=thisConnection.CreateCommand(); //
thisCommand.CommandText="SELECT * FROM Intro";
OleDbDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",thisReader["ID"],thisReader["TheName"]);
}
thisReader.Close();
thisConnection.Close();