0

When I execute this

    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();

and

 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();

and

 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();

        }

Database-malkontrol table enter image description here

** I get this error**

The input string was not in the correct format

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);

I think 2 value members are colliding. Could some informed coders explain where is my fault?

Community
  • 1
  • 1
  • Look at the following question as a lot of problems of your code seem similar to the other: https://stackoverflow.com/questions/49966659/conversion-error-from-date-time-to-string-format/49966833#49966833 – Kzryzstof Apr 22 '18 at 21:39
  • I didnt understand your solve it is strange.Can you give me small example about this@Kzrystof – TrySomethingg Apr 22 '18 at 21:45
  • [Almost certainly a sock puppet account](https://stackoverflow.com/q/49968124/1070452). This is the third time the question has been posted. At some point you will want to learn how to use the debugger - its easier than making new SO accounts when you burn them out – Ňɏssa Pøngjǣrdenlarp Apr 22 '18 at 21:46
  • 1
    The idea is to used Parameters property of the SQLCommand instead of building your own query... That might solve your problem. – Kzryzstof Apr 22 '18 at 21:47
  • Never ever glue things together to make SQL. Use SQL parameters always - this is one of the many problems they solve. – Ňɏssa Pøngjǣrdenlarp Apr 22 '18 at 21:48
  • I will learn sql parameters thank you for helps – TrySomethingg Apr 22 '18 at 21:48

1 Answers1

0

Check your datetimepicker date format,if database data type is datetime insert it as something like datatimepicker1.value.tostring("yyyy-MM-dd").also why do you need to convert combobox value.try inserting combobox.selectedvalue.that will insert the Id of the combo box selected item.because if the combox box value is a string it won't be converted to uint32 as u want it.

Peter
  • 111
  • 1
  • 1
  • 7