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.

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


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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.