i am developing a small program with MS Access database in VB.net. the problem is the code below gives this error
"no value given for one or more required parameters" also i have one item in the datagrid with a string with spaces i m not able to add it to the database
variables
"no value given for one or more required parameters" also i have one item in the datagrid with a string with spaces i m not able to add it to the database
variables
Public Sub UpdateDatabase(ByVal strType As String, ByVal intCache As Integer)
Dim strTableName = FetchDestTable(strType, intCache)
Dim row = frmMain.gridData.RowCount - 1
Dim col = frmMain.gridData.ColumnCount - 1
Dim r = 0
Dim c = 0
strSQL = "INSERT INTO " & strTableName(1) & " VALUES ("
For c = 0 To col
Dim var As Object
Dim strHead As String = frmMain.gridData.Columns(c).HeaderText
If Not (frmMain.gridData.Item(c, r).Value Is Nothing Or IsDBNull(frmMain.gridData.Item(c, r).Value)) Then
If strHead.ToLower.Contains("dt") Then
Dim var1 As Date = (frmMain.gridData.Item(c, r).Value)
var = var1.ToShortDateString
ElseIf (strHead.ToLower.Contains("time") Or strHead.ToLower.Contains("from") Or strHead.ToLower.Contains("to")) And Not (strHead.ToLower.Contains("tor")) Then
Dim var1 As Date = (frmMain.gridData.Item(c, r).Value)
var = var1.ToShortTimeString
Else
var = frmMain.gridData.Item(c, r).Value
End If
Else
var = "null"
End If
If c = 0 And var.ToString = "null" Then
MessageBox.Show("NULL value of Primary key ,error loading row No. " & r.ToString, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Exit Sub
Else
strSQL = strSQL & var.ToString
End If
If c = col Then
strSQL = strSQL & ");"
Else
strSQL = strSQL & ","
End If
Next
MsgBox(strSQL)
Try
dbCmd.CommandText = strSQL1
dbCmd.Connection = dbConn
dbConn.Open()
dbCmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
dbConn.Close()
End Sub