C#获取SQL数据库中的某一列值

2025-02-24 10:28:15
推荐回答(2个)
回答1:

SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=database;user id=sa;password=12345;min pool size=4;max pool size=100;");
SqlDataAdapter sdaTest = new SqlDataAdapter("select B from A", con);
DataTable dtblTest = new DataTable();
try
{
sdaTest.Fill(dtblTest);
}
catch (Exception ex)
{

throw;
}

回答2:

dataTable dt=类.方法名("select * from A")

string StrValuedt=dt.rows[0]["B"].tostring();

StrValuedt就是你要的值!

不懂再问我!!!