c#中直接取出sql中表中字段的值
1private void button1_Click(object sender, EventArgs e)
2{
3string cha = "select * from tushu";
4using (SqlConnection conn = new SqlConnection("server=CHENCHAN-PC\\CC;database=chenchan;uid=sa;pwd="))
5{
6DataSet chenchan = new DataSet();
7SqlDataAdapter da = new SqlDataAdapter(cha,conn);
8conn.Open();
9da.Fill(chenchan,"tushu");
10
11// str就是第一行,第一列的值
12string str = chenchan.Tables[0].Rows[0][0].ToString();
13conn.Close();
14}
15}
16
2{
3string cha = "select * from tushu";
4using (SqlConnection conn = new SqlConnection("server=CHENCHAN-PC\\CC;database=chenchan;uid=sa;pwd="))
5{
6DataSet chenchan = new DataSet();
7SqlDataAdapter da = new SqlDataAdapter(cha,conn);
8conn.Open();
9da.Fill(chenchan,"tushu");
10
11// str就是第一行,第一列的值
12string str = chenchan.Tables[0].Rows[0][0].ToString();
13conn.Close();
14}
15}
16