private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=(local);Initial Catalog=Tesk;Integrated Security=True";            conn.Open();;
            string sql = "select @a=pwd from pwd where num='" + textBox1.Text + "'";
            SqlCommand sqlCommand = new SqlCommand(sql, conn);
            sqlCommand.CommandType = CommandType.Text;
            conn.Open();
            string a = sqlCommand.ExecuteScalar();最后一句错了,我只想把pwd的值赋值给a

解决方案 »

  1.   

    sql = "select @a=pwd from pwd where num='" + textBox1.Text + "'";
    =〉
    sql = "update from pwd set @a=pwd where num='" + textBox1.Text + "'";
      

  2.   

    string sql = "select pwd from pwd where num='" + textBox1.Text + "'";
      

  3.   

    如果你的表叫"pwd"的话,如果不是这样,from后面写表名。
      

  4.   

    string sql = "select @a=pwd from pwd where num='" + textBox1.Text + "'";这句学错了应该是string sql = "select pwd from pwd where num='" + textBox1.Text + "'";