C#如何在textBox上显示数据库文本并且可以进行修改20分,行了不

这个太简单了,要复杂点的,比如表里有a1,a2,a3,a4,a5这些字段,然后读到(textBox1,textBox2,textBox3,……到5为止,然后可以对其进行修改.

--显示:
using (SqlConnection conn = new SqlConnection("server=(SQL服务器名称);user id=sa;password=(SQL密码);database=连接的数据库"))
{
string sql = "select * from mess where stu_name=@a,@b,@c,@d,@e";
SqlCommand com = new SqlCommand(sql,conn);
com.Parameters.AddWithValue("@name", textBox1.Text);
com.Parameters.AddWithValue("@name", textBox2.Text);
com.Parameters.AddWithValue("@name", textBox3.Text);
com.Parameters.AddWithValue("@name", textBox4.Text);
com.Parameters.AddWithValue("@name", textBox5.Text);
conn.Open();
SqlDataReader dr = com.ExecuteReader();

if (dr.Read())
{
textBox1.Text = dr["第一列的列名"].ToString();
textBox2.Text = dr["第二列的列名"].ToString();
textBox3.Text = dr["第三列的列名"].ToString();
textBox4.Text = dr["第思列的列名"].ToString();
textBox5.Text = dr["第五列的列名"].ToString();
}
修改

}
}

string sql = "update mess set 第一列的列名=@a,第二列的列名=@b,第三列的列名=@c,第四列的列名=@d,第五列的列名=@e";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
com.Parameters.AddWithValue("@a", textBox1.Text);
com.Parameters.AddWithValue("@b", textBox2.Text);
com.Parameters.AddWithValue("@c", textBox3.Text);
com.Parameters.AddWithValue("@d", textBox4.Text);
com.Parameters.AddWithValue("@e", textBox5.Text);
com.ExecuteNonQuery();
MessageBox.Show("修改成功");
}

}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-26
就是数据邦定到 textbox 是吧,很简单。不过主样说不好说吧。最好是做个实例给你。
加Q可远程操作。
第2个回答  2012-07-27
推荐你去看下传直播客的基础视频,很有用的
相似回答