Dear Sir,
How to write these codes correctly.
It displays following tooltip

Too many arguments to 'public function iif(expression as bolean, truepart as object, falsepart as object) as object'.

Dim cmd As New SqlClient.SqlCommand("Insert Into master (code) Values (@code)", con)
                cmd.Parameters.AddWithValue(IIf(Val(Me.TxtCod) = 0, "Null", "@code", Val(Me.TxtCod)))
cmd.Parameters.AddWithValue(IIf(Val(Me.TxtCod) = 0, "Null", "@code", Val(Me.TxtCod)))

Note that IIF takes 3 parameters, adjust parenthesis of that.

cmd.Parameters.AddWithValue("@code", IIf(Val(Me.TxtCod) = 0, "Null", Val(Me.TxtCod)))

Please mark trhread closed if this helps.

cmd.Parameters.AddWithValue(IIf(Val(Me.TxtCod) = 0, "Null", "@code", Val(Me.TxtCod)))

Note that IIF takes 3 parameters, adjust parenthesis of that.

cmd.Parameters.AddWithValue("@code", IIf(Val(Me.TxtCod) = 0, "Null", Val(Me.TxtCod)))

Please mark trhread closed if this helps.

Dear Sir,
This line work fine

cmd.Parameters.AddWithValue("@desc", IIf(Len(Me.TxtDes) = 0, "Null", (Me.TxtDes)))

this line generates error as
value of type 'system.windows.form.textbox' can not be converted to "string".
trim is used in this line

cmd.Parameters.AddWithValue("@desc", IIf(Len(Me.TxtDes) = 0, "Null", trim(Me.TxtDes)))

Please help to send trimmed value to database while using above line

Please add dot text in your code...

cmd.Parameters.AddWithValue("@desc", IIf(Len(Me.TxtDes.Text) = 0, "Null", trim(Me.TxtDes.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.