In response to OPs comments to Solution 1 ..
MyParm = cmd.Parameters.Add("@CD_CUSTOMER", SqlDbType.Int)
MyParm.Value = Int32.TryParse(txt_CD_CUSTOMER.Text, unused)
MyParm = cmd.Parameters.Add("@COMPANY_NAME", SqlDbType.NVarChar)
MyParm.Value = lbl_COMPANY_NAME.Text.ToString
MyParm = cmd.Parameters.Add("@EXP_DATE", SqlDbType.Date)
MyParm.Value = DateTime.ParseExact(txt_EXP_DATE.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Quote:
tried this solution but doesn't work
I'm not surprised that it doesn't work - see
MyParm = cmd.Parameters.Add("@CD_CUSTOMER", SqlDbType.Int)
MyParm.Value = Int32.TryParse(txt_CD_CUSTOMER.Text, unused)
Int.TryParse()
returns a boolean - not a integer. So you can't just assign that to your parameter. Look at the documentation
Int32.TryParse Method (System) | Microsoft Docs[
^]. The clue is in your variable
unused
- you haven't used the return value
but you should haveThat piece of code should look more like (note not tested)
MyParm = cmd.Parameters.Add("@CD_CUSTOMER", SqlDbType.Int)
If Int32.TryParse(txt_CD_CUSTOMER.Text, unused) Then
MyParm.Value = unused
Else
End If
You've done similar with the txt_EXP_DATE but don't have an out value at all for that - look at the documentation
DateTime.TryParseExact Method (System) | Microsoft Docs[
^] or have a look at the examples in
https://www.dotnetperls.com/datetime-tryparse[
^]