0

Hi Everyone,
ColumnName DataType Length AllowNulls
sampleKey char 10
engDesc char 40 Yes
frDesc char 40 Yes
When I try to add a record,if the Textbox is empty then I am getting an errror. If it's not empty then it adds to the table. But in database, I checked those fields to accept null values. Here is the sample code below.

<VBCODE>
Dim sqlQuery as String = "INSERT INTO SampleTable(sampleKey,engDesc,frDesc) VALUES (@key,@english,@french)"

Dim cmd As SqlCommand = SqlConnection1.CreateCommand

cmd.Parameters.Add("@key", txtKey.Text)
cmd.Parameters.Add("@english", txtEnglish.Text)
cmd.Parameters.Add("@french", txtFrench.Text)
cmd.CommandType = CommandType.Text
cmd.CommandText = sqlQuery

SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()
</VBCODE>

1
Contributor
2
Replies
3
Views
12 Years
Discussion Span
Last Post by baba0880
0

Error Message
Prepared statement '(@key char(10),@english char(40),@french char(40)) INSERT expects parameter @english,which was not supplied

0

cmd.Parameters.Add("@key", SqlDbType.Char).Value = IIf(txtKey.Text = String.Empty, DBNull.Value, txtKey.Text)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.