|
|
|
ต้องการบันทึกข้อมูลจาก DataGridView ลง Database MySQL |
|
|
|
|
|
|
|
รบกวนช่วยดูให้หน่อยครับ คือมันขึ้น Error ว่า "Fatal error encountered during command execution." แต่ไม่รู้จะแก่ตรงไหนครับ
Code (VB.NET)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Call Conntion()
For i As Integer = 0 To Rent.DataGridView1.RowCount - 1
If Not Rent.DataGridView1.Rows(i).IsNewRow Then
Dim Rent_ID As Integer
Rent_ID = Convert.ToInt32(Rent.DataGridView1.Item(0, i).Value)
MyCmd = New MySql.Data.MySqlClient.MySqlCommand(StrSQL, MySQLConn)
MyCmd.Connection = MySQLConn
MyCmd.CommandText = "INSERT INTO rent VALUES (" & Rent_ID & ",@Mem_ID,@Mem_FName,@Mem_LName,@Mem_Phone,@Book_ID,@Barcode_ID,@Book_NameTH,@Book_NameEN,@dateStart,@dateEnd)"
MyCmd.Parameters.Add("@Mem_ID", MySqlDbType.VarChar).Value = Rent.txtMemID.Text
MyCmd.Parameters.Add("@Mem_FName", MySqlDbType.VarChar).Value = Rent.txtName.Text
MyCmd.Parameters.Add("@Mem_LName", MySqlDbType.VarChar).Value = Rent.txtLName.Text
MyCmd.Parameters.Add("@Mem_Phone", MySqlDbType.VarChar).Value = Rent.txtPhoneNumber.Text
MyCmd.Parameters.Add(New MySqlParameter("@Book_ID", Rent.DataGridView1.Rows(i).Cells(0).Value))
MyCmd.Parameters.Add(New MySqlParameter("@Barcode_ID", Rent.DataGridView1.Rows(i).Cells(1).Value))
MyCmd.Parameters.Add(New MySqlParameter("@Book_NameTH", Rent.DataGridView1.Rows(i).Cells(2).Value))
MyCmd.Parameters.Add(New MySqlParameter("@Book_NameEN", Rent.DataGridView1.Rows(i).Cells(3).Value))
MyCmd.Parameters.Add(New MySqlParameter("@dateStart", Rent.DataGridView1.Rows(i).Cells(7).Value))
MyCmd.Parameters.Add(New MySqlParameter("@dateEnd", Rent.DataGridView1.Rows(i).Cells(8).Value))
End If
MyCmd.ExecuteNonQuery()
MyCmd.Parameters.Clear()
Next
MessageBox.Show("บันทึกข้อมูลแล้ว", "บันทึกข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
MySQLConn.Close()
Rent.DataGridView1.Rows.Clear()
End Sub
Tag : .NET, MySQL, Win (Windows App), VB.NET, VS 2012 (.NET 4.x)
|
ประวัติการแก้ไข 2015-10-26 20:53:23 2015-10-26 22:07:53
|
|
|
|
|
Date :
2015-10-26 20:40:09 |
By :
Jamesillion |
View :
2035 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (VB.NET)
'*** Insert to Database ***'
Dim objConn As New MySqlConnection
Dim strConnString, strSQL As String
strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false;"
strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
" VALUES " & _
" (?sName,?sFilesName,?sFilesType)"
objConn.ConnectionString = strConnString
objConn.Open()
Dim objCmd As New MySqlCommand(strSQL, objConn)
objCmd.Parameters.Add("?sName", MySqlDbType.VarChar).Value = Me.txtName.Text
objCmd.Parameters.Add("?sFilesName", MySqlDbType.Binary).Value = imbByte
objCmd.Parameters.Add("?sFilesType", MySqlDbType.VarChar).Value = strMIME
objCmd.ExecuteNonQuery()
objConn.Close()
objConn = Nothing
การ Insert แบบ MySQL ครับ
|
|
|
|
|
Date :
2015-10-27 13:07:02 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (VB.NET)
Me.txtName.Text = String.Empty
อยากให้อะไรว่างก็ใส่ไปครับ
|
|
|
|
|
Date :
2015-10-27 16:51:00 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|