Dim cm As New SqlCommand
cm.Connection = con
cm.Connection.Open()
cm.CommandText = "Insert into tblsim ([sn],[dir],[alt],[plans],[rate],[addon],[cm]) values (@sn,@dir,@alt,@plans,@rate,@addon,@cm)"
If tssn.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@sn", SqlDataType.Numeric).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@sn", SqlDataType.Numeric).Value = tssn.Text
End If
If tsdir.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@dir", SqlDataType.Numeric).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@dir", SqlDataType.Numeric).Value = tsdir.Text
End If
If tsalt.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@alt", SqlDataType.Numeric).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@alt", SqlDataType.Numeric).Value = tsalt.Text
End If
If cmbplans.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@plans", SqlDataType.Numeric).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@plans", SqlDataType.Numeric).Value = cmbplans.Text
End If
If cmbrate.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@rate", SqlDataType.NVarChar).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@rate", SqlDataType.NVarChar).Value = cmbrate.Text
End If
If cmbaddon.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@addon", SqlDataType.NVarChar).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@addon", SqlDataType.NVarChar).Value = cmbaddon.Text
End If
If tscm.Text.Trim.Length = 0 Then
cm.Parameters.AddWithValue("@cm", SqlDataType.NVarChar).Value = DBNull.Value
Else
cm.Parameters.AddWithValue("@cm", SqlDataType.NVarChar).Value = tscm.Text
End If
cm.ExecuteNonQuery()
MsgBox("Record has been saved successfully", MsgBoxStyle.Information)
cm.Connection.Close()
CREATE TABLE [dbo].[tblsim](
[simid] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[sn] [numeric](18, 0) NOT NULL,
[dir] [numeric](18, 0) NOT NULL,
[alt] [numeric](18, 0) NULL,
[plans] [numeric](18, 0) NULL,
[rate] [numeric](18, 0) NULL,
[addon] [numeric](18, 0) NULL,
[cm] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tblsim_1] PRIMARY KEY CLUSTERED
(
[simid] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
What I have tried:
I'm facing problem when I try to insert data: Error in converting data type from NVarchar to Numeric.
To be noted that value to be inserted in column 'simid' is 20 digit long. eg 28808399937872736628.
I also tried to insert by changing the column's data type to 'BigInt' and Nvarchar but still it does not work!
Regards: Shahid