.Net Program Codes
3 posters
Page 1 of 1
Re: .Net Program Codes
Why display syntax error in INSERT INTO ?
[You must be registered and logged in to see this link.]
Try
'get connection string declared in the Module1.vb and assing it to conn variable
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL = "INSERT INTO 30/5/2013 (ID, ProductName, Quantity, SellingPrice) "
sSQL = sSQL & "VALUES (@ID, @ProductName, @Quantity, @SellingPrice)"
cmd.CommandText = sSQL
cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IIf(Len(Trim(Me.txtID.Text)) > 0, Me.txtID.Text, DBNull.Value)
cmd.Parameters.Add("@ProductName", OleDbType.VarChar).Value = IIf(Len(Trim(Me.txtProduct.Text)) > 0, Me.txtProduct.Text, DBNull.Value)
cmd.Parameters.Add("@Quantity", OleDbType.Numeric).Value = IIf(Len(Trim(Me.txtQuantity.Text)) > 0, Me.txtQuantity.Text, DBNull.Value)
cmd.Parameters.Add("@SellingPrice", OleDbType.Currency).Value = IIf(Len(Trim(Me.txtSellingPrice.Text)) > 0, Me.txtSellingPrice.Text, DBNull.Value)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
[You must be registered and logged in to see this link.]
Try
'get connection string declared in the Module1.vb and assing it to conn variable
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL = "INSERT INTO 30/5/2013 (ID, ProductName, Quantity, SellingPrice) "
sSQL = sSQL & "VALUES (@ID, @ProductName, @Quantity, @SellingPrice)"
cmd.CommandText = sSQL
cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IIf(Len(Trim(Me.txtID.Text)) > 0, Me.txtID.Text, DBNull.Value)
cmd.Parameters.Add("@ProductName", OleDbType.VarChar).Value = IIf(Len(Trim(Me.txtProduct.Text)) > 0, Me.txtProduct.Text, DBNull.Value)
cmd.Parameters.Add("@Quantity", OleDbType.Numeric).Value = IIf(Len(Trim(Me.txtQuantity.Text)) > 0, Me.txtQuantity.Text, DBNull.Value)
cmd.Parameters.Add("@SellingPrice", OleDbType.Currency).Value = IIf(Len(Trim(Me.txtSellingPrice.Text)) > 0, Me.txtSellingPrice.Text, DBNull.Value)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
waimuntupai- Newbie
- Posts : 1
Join date : 2013-06-01
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|