日期:2014-05-17  浏览次数:20913 次

在winform里怎么把查到的abc分别赋值给ABC
winform sql 查询赋值
SqlCommand cmd = new SqlCommand("select a,b,c from zhengshib where ZCM='" + strREG + "'and ID='" + rjid + "'", data.conn);

在winform里怎么把查到的abc分别赋值给ABC

------解决方案--------------------
SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=123456;");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select [id],[name],[password] from users where name='guwei'", conn);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                this.textBox1.Text = reader.GetInt32(0) + "";
                this.textBox2.Text = reader[1].ToString();
                this.textBox3.Text = reader.GetValue(2).ToString();
            }

------解决方案--------------------
SqlCommand cmd = new SqlCommand("select a,b,c from zhengshib where ZCM='" + strREG + "'and ID='" + rjid + "'", data.conn);
DataTable table = DBProvider.DefaultDBOperator.GetDataTable(cmd);
if (table.Rows.Count > 0)
{
DataRow dr=table.Rows[0];
string strA = dr["a"].ToString();
string strB = dr["b"].ToString();
string strC = dr["c"].ToString();
}