当我执行这个的时候
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();
}
数据库malkontrol表在此处输入图像描述
我得到这个错误
输入字符串的格式不正确
mysqlcommand komut=new mysqlcommand(“插入mydb.malkontrol(tarih、birimtur、harcanan、kalan、santiye\u idsantiye、malzemeler\u idmalzemeler)值(“+datetimepicker1.text+”、“+degisceklab.text+”、“+textbox3.text+”、“+textbox4.text+”、“+convert.touint32(combobobox1.text)+”、“+convert.touint32(combobox2.text)+”)”),巴格兰蒂);
我认为两个价值观成员在冲突。一些知情的程序员能解释一下我的错在哪里吗?
1条答案
按热度按时间qacovj5a1#
检查datetimepicker日期格式,如果数据库数据类型为datetime,请将其插入为类似datatimepicker1.value.tostring(“yyyy-mm-dd”)的内容。另外,为什么需要转换combobox值。请尝试插入combobox.selectedvalue。这将插入combobox所选项的id。因为如果combobox值是字符串,它将不会按您的需要转换为uint32。