Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why this error giving.I want to submit 17 field's data out of 34.
only want to submit these below value to database
v1 = TextBox1.Text.Trim()
v2 = TextBox2.Text.Trim()
v3 = TextBox3.Text.Trim()
v4 = TextBox4.Text.Trim()
v5 = TextBox5.Text.Trim()
v6 = TextBox6.Text.Trim()
v7 = TextBox7.Text.Trim()
v8 = TextBox8.Text.Trim()
v9 = TextBox9.Text.Trim()
v10 = ta1.Value
v11 = ta2.Value
v12 = ta3.Value
v13 = ta4.Value
v14 = ta5.Value
v15 = ta6.Value
v16 = ta7.Value
v17 = ta8.Value

Error - No value given for one or more required parameters.
My code given below
VB
s = TextBox5.Text.Trim()
     Try
         cn.Open()
         cmd = New OleDbCommand("Select ccode from template where vmail='" & s & "'", cn)
         dr = cmd.ExecuteReader
         dr.Read()
         b = dr.HasRows()
         If b Then
             Label2.Text = "Record already EXIST"
             TextBox1.Focus()
             v1 = TextBox1.Text.Trim()
             v2 = TextBox2.Text.Trim()
             v3 = TextBox3.Text.Trim()
             v4 = TextBox4.Text.Trim()
             v5 = TextBox5.Text.Trim()
             v6 = TextBox6.Text.Trim()
             v7 = TextBox7.Text.Trim()
             v8 = TextBox8.Text.Trim()
             v9 = TextBox9.Text.Trim()
             v10 = ta1.Value
             v11 = ta2.Value
             v12 = ta3.Value
             v13 = ta4.Value
             v14 = ta5.Value
             v15 = ta6.Value
             v16 = ta7.Value
             v17 = ta8.Value

             v18 = TextBox10.Text.Trim()
             v19 = TextBox11.Text.Trim()
             v20 = TextBox12.Text.Trim()
             v21 = TextBox13.Text.Trim()
             v22 = TextBox14.Text.Trim()
             v23 = TextBox15.Text.Trim()
             v24 = TextBox16.Text.Trim()
             v25 = TextBox17.Text.Trim()
             v26 = TextBox18.Text.Trim()
             v27 = ta9.Value
             v28 = ta10.Value
             v29 = ta11.Value
             v30 = ta12.Value
             v31 = ta13.Value
             v32 = ta14.Value
             v33 = ta15.Value
             v34 = ta16.Value
         Else
             Try
                 str = "Insert into template (tname,tdob,tsex,tmo,tmail,tcity,tpin,tst,tco,tca,tskill,tedu,ttrain,texpt,tproj,texp,tint) values('" & v1 & "','" & v2 & "','" & v3 & "','" & v4 & "','" & v5 & "','" & v6 & "','" & v7 & "','" & v8 & "','" & v9 & "','" & v10 & "','" & v11 & "','" & v12 & "','" & v13 & "','" & v14 & "','" & v15 & "','" & v16 & "','" & v17 & "')"
                 cmd = New OleDbCommand(str, cn)
                 cmd.ExecuteNonQuery()
                 Label2.Text = "Record Added"
             Catch ex As Exception
                 Response.Write(ex.Message)
             End Try
         End If
     Catch ex As Exception
         Response.Write(ex.Message)
     End Try


     cn.Close()
Posted
Updated 7-Nov-11 21:43pm
v3

1 solution

Please, don't do it that way.
That is a major recipe for an SQL Injection attack - use Parametrized queries instead:
VB
str = "INSERT INTO template (tname,tdob,tsex,tmo,tmail,tcity,tpin,tst,tco,tca,tskill,tedu,ttrain,texpt,tproj,texp,tint) VALUES (@tname,@tdob,@tsex,@tmo...
cmd.Parameters.AddWithValue("@tname",TextBox1.Text.Trim())
cmd.Parameters.AddWithValue("@tdob",TextBox2.Text.Trim())
...
In addition, rename your controls: you may remember that TextBox7 is the "pin" today - but you won't next week. Call it something related to it's usage!
Then, you can add a check for null values to your parameter stting, and feed DBNull.Value to the database instaed, which will cure your problem.
 
Share this answer
 
Comments
Janardan Pandey 8-Nov-11 4:07am    
Not clear, help me for complete insert statment like.Because this is my first time implimentation like this insert statment
codejet 11-Nov-11 17:50pm    
I agree with OriginalGriff.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900