0

I have code like this:

con.Open();

cmd = new SqlCommand("insert into Penawaran (ID_Paket,Jenis_Paket,Harga_Paket) Values (@ID_Paket,@Jenis_Paket,@Harga_Paket", con);

cmd.Parameters.AddWithValue("@ID_Paket", txtIDPaket.Text);
cmd.Parameters.AddWithValue("@Jenis_Paket", txtjenisPaket.Text);
cmd.Parameters.AddWithValue("@Harga_Paket", txtHargaPaket.Value); // this is int sir how to insert it, still error i write like this

cmd.ExecuteNonQuery();
con.Close();

Please help me to inside int to my table Paket.

3
  • Can you post the error you get? Commented Jan 16, 2016 at 10:41
  • You might want to read this and replace the calls to AddWithValue(name,value) with Add(name, sqlDbType).Value = value. Commented Jan 16, 2016 at 11:16
  • You should check out Can we stop using AddWithValue() already? and stop using .AddWithValue() - it can lead to unexpected and surprising results... Commented Jan 16, 2016 at 11:35

2 Answers 2

3

There is a missing parenthesis at the end of Insert query

 INSERT INTO Penawaran (ID_Paket,Jenis_Paket,Harga_Paket)
               VALUES (@ID_Paket,@Jenis_Paket,@Harga_Paket) --Here
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my god i forget to change it, Thanks sir :D
0

Try this

           SqlConnection con = new SqlConnection();
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into Penawaran (ID_Paket,Jenis_Paket,Harga_Paket) Values (@ID_Paket,@Jenis_Paket,@Harga_Paket", con));
            cmd.Parameters.Add("@ID_Paket", SqlDbType.Int);
            cmd.Parameters.Add("@Jenis_Paket", SqlDbType.VarChar);
            cmd.Parameters.Add("@Harga_Paket", SqlDbType.VarChar); // this is int sir how to insert it, still error i write like this

            cmd.Parameters["@ID_Paket"] = int.Parse(txtIDPaket.Text);
            cmd.Parameters["@Jenis_Paket"] = txtjenisPaket.Text;
            cmd.Parameters["@Harga_Paket"]  = txtHargaPaket.Value; // this is int sir how to insert it, still error i write like this
            cmd.ExecuteNonQuery();
            con.Close();

1 Comment

Your third line is missing the closing paranthesis after the value - as the OP did :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.