mssql数据库连接方法(c#)
时间:2011-04-11 来源:烈日轨迹
public void BindData()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data source=(local);initial catalog=Test;user id=sa;pwd=123456;";
conn.Open();
string strCmd = "SELECT * FROM TestOne";
SqlDataAdapter myDataAdapter;
DataSet myDataSet = new DataSet();
myDataAdapter = new SqlDataAdapter(strCmd, conn);
myDataAdapter.Fill(myDataSet, "TestOne");
Label1.Text = myDataSet.Tables[0].Rows[0]["Name"].ToString();
}
说明:数据库:Test ;数据表:TestOne ;表字段:Name
相关阅读 更多 +