2017-01-26 6 views
0

私はtextboxの値をSQLデータベースに保存するコードを書いていましたが、うまくいきましたが、SQLデータベースにdatagridviewの値を挿入しようとしましたが、 ...私のコードはSQLデータベースにデータ値を格納していません

Private Sub savenprint() 
     If Not db.con.State = ConnectionState.Open Then 
      db.dbOpen() 
      With db.cmd 
       .Connection = db.con 
       .CommandText = "INSERT INTO Reciept VALUES ('" & txtRecieptNo.Text & "','" & TransDate.Text & "','" & txtSubTotal.Text & "') " 
       .ExecuteNonQuery() 
      End With 
      'to save data of DGVOrderedList into RecieptDescription 
      For Each row As DataGridViewRow In DGVorderedList.Rows 

       MsgBox(row.Cells(1).Value) 
       With db.cmd 
        .Connection = db.con 
        .CommandText = "INSERT INTO billDescription VALUES ('" & Val(txtRecieptNo.Text) & "','" & row.Cells(1).Value & "','" & row.Cells(2).Value & "','" & row.Cells(4).Value & "','" & row.Cells(3).Value & "','" & row.Cells(5).Value & "')" 
       End With 
       MsgBox("Record Saved!") 
      Next 



     End If 
     db.dbClose() 
    End Sub 
+0

使用のSQLパラメータ。 –

答えて

1
  With db.cmd 
       .Connection = db.con 
       .CommandText = "INSERT INTO billDescription VALUES ('" & Val(txtRecieptNo.Text) & "','" & row.Cells(1).Value & "','" & row.Cells(2).Value & "','" & row.Cells(4).Value & "','" & row.Cells(3).Value & "','" & row.Cells(5).Value & "')" 
       .ExecuteNonQuery() 
      End With 
関連する問題