SqlConnection cn = new SqlConnection(app);
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "select * from Accountnumber where name='admin'";
cmd.CommandType = CommandType.Text;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(ds);
da.Fill(dt);
MessageBox.Show(ds.Tables[0].Columns[1].ToString());
但是我想得出的是password下面的admin,,不會做,求大神幫助
cmd.Parameters.Add(new SqlParameter("@txt1", txt1));
cmd.CommandText = "select * from student where name=@txt1";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = cmd;
da.Fill(dt);
DataRow dr = dt.Rows[0];
txt_2id.Text = dr[0].ToString();
用datarow()就可以了