c#中向MySQL数据库的某一字段添加文本框里的内容。
MySqlConnectionconn=newMySqlConnection("Host=Localhost;UserName=root;Password=root;Da...
MySqlConnection conn = new MySqlConnection("Host=Localhost;UserName=root;Password=root;Database=oasystem;Port=3306;CharSet=utf8;Allow Zero Datetime=true");
conn.Open();
string sql = "insert into chat(neirong) values( {0} where user='"+comboBox1 .Text +"')";
sql = string.Format(sql, textBox2.Text);
using (MySqlCommand cmd = new MySqlCommand(sql , conn))
{
cmd.ExecuteNonQuery();
}哪里有错 请教大神! 展开
conn.Open();
string sql = "insert into chat(neirong) values( {0} where user='"+comboBox1 .Text +"')";
sql = string.Format(sql, textBox2.Text);
using (MySqlCommand cmd = new MySqlCommand(sql , conn))
{
cmd.ExecuteNonQuery();
}哪里有错 请教大神! 展开
推荐于2016-02-22
展开全部
private DataSet ds2 = new DataSet();
private bool isadd2 = false;
private bool isdel2 = false;
private void DataBind()
{
this.dataGridView1.AutoGenerateColumns = false;
string sql = "select jhid,psid,jpid,jpbh,jpmc,jply,jpxz,jpgg,jpsl from lab_wbshjh_psxx_xckhjb order by jpid";
SqlDataAdapter sda = new SqlDataAdapter(sql, 【数据库连接类】);
ds2.Clear();
sda.Fill(ds2, "lab_wbshjh_psxx_xckhjb");
this.dataGridView1.DataSource = ds2.Tables["lab_wbshjh_psxx_xckhjb"];
this.comboBox12.DataBindings.Clear();
this.comboBox12.DataBindings.Add(new Binding("Text", ds2.Tables["lab_wbshjh_psxx_xckhjb"], "jpbh"));
}
绑定就可以了。
private bool isadd2 = false;
private bool isdel2 = false;
private void DataBind()
{
this.dataGridView1.AutoGenerateColumns = false;
string sql = "select jhid,psid,jpid,jpbh,jpmc,jply,jpxz,jpgg,jpsl from lab_wbshjh_psxx_xckhjb order by jpid";
SqlDataAdapter sda = new SqlDataAdapter(sql, 【数据库连接类】);
ds2.Clear();
sda.Fill(ds2, "lab_wbshjh_psxx_xckhjb");
this.dataGridView1.DataSource = ds2.Tables["lab_wbshjh_psxx_xckhjb"];
this.comboBox12.DataBindings.Clear();
this.comboBox12.DataBindings.Add(new Binding("Text", ds2.Tables["lab_wbshjh_psxx_xckhjb"], "jpbh"));
}
绑定就可以了。
追问
不用dataGridView的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询