【发布时间】:2018-04-22 21:28:10
【问题描述】:
当我执行此操作时
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = true;
MySqlConnection baglanti = new MySqlConnection("Server=localhost;Database=mydb;Uid=root;Pwd='';");
baglanti.Open();
MySqlCommand komut = new MySqlCommand("select*from mydb.malzemeler", baglanti);
MySqlDataReader oku = komut.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(oku);
comboBox2.DataSource = dt;
comboBox2.DisplayMember = "malzemeisim";
comboBox2.ValueMember = "idmalzemeler";
MySqlCommand komut2 = new MySqlCommand("select*from mydb.santiye", baglanti);
MySqlDataReader oku2 = komut2.ExecuteReader();
DataTable dt2 = new DataTable();
dt2.Load(oku2);
comboBox1.DataSource = dt2;
comboBox1.DisplayMember = "santiye_ad";
comboBox1.ValueMember = "idsantiye";
baglanti.Close();
和
MySqlConnection baglanti = new MySqlConnection("Server=localhost;Database=mydb;Uid=root;Pwd='';");
baglanti.Open();
MySqlCommand komut = new MySqlCommand("insert into mydb.malkontrol(tarih,birimtur,harcanan,kalan,santiye_idsantiye,malzemeler_idmalzemeler) VALUES ('" + dateTimePicker1.Text + "','" + degiscekLabel.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + Convert.ToUInt32(comboBox1.Text) + "','" + Convert.ToUInt32(comboBox2.Text)+"')", baglanti);
MessageBox.Show("Kayıt Başarıyla eklendi");
komut.ExecuteNonQuery();
baglanti.Close();
和
MySqlConnection baglanti = new MySqlConnection("Server=localhost;Database=mydb;Uid=root;Pwd='';");
baglanti.Open();
string query = "SELECT malzemebirimtur FROM malzemeler WHERE malzemeisim= '" + comboBox2.Text + "'";
MySqlCommand komut = new MySqlCommand(query, baglanti);
MySqlDataReader dr = komut.ExecuteReader();
while (dr.Read())
{
degiscekLabel.Text = dr.GetValue(0).ToString();
}
数据库控制表 enter image description here
** 我收到此错误**
输入的字符串格式不正确
MySqlCommand komut = new MySqlCommand("插入 mydb.malkontrol(tarih,birimtur,harcanan,kalan,santiye_idsantiye,malzemeler_idmalzemeler) VALUES ('" + dateTimePicker1.Text + "','" + degiscekLabel.Text + "', '" + textBox3.Text + "','" + textBox4.Text + "','" + Convert.ToUInt32(comboBox1.Text) + "','" + Convert.ToUInt32(comboBox2.Text)+"') ", 巴格兰蒂);
我认为 2 个价值成员正在发生冲突。一些知情的编码人员能否解释我的错在哪里?
【问题讨论】:
-
看看下面的问题,因为你的代码中的很多问题看起来都和其他的很相似:stackoverflow.com/questions/49966659/…
-
我不明白你的解决方法很奇怪。你能给我一个关于这个的小例子吗@Kzrystof
-
Almost certainly a sock puppet account。这是第三次发布这个问题。在某些时候,您会想学习如何使用调试器——它比烧掉新的 SO 帐户更容易
-
这个想法是使用 SQLCommand 的 Parameters 属性而不是构建自己的查询...这可能会解决您的问题。
-
永远不要把东西粘在一起来创建 SQL。始终使用 SQL 参数 - 这是他们解决的众多问题之一。
标签: c# mysql visual-studio