VB 2010 ฐานข้อมูล Mysql ดึงข้อมูลมาแสดงใน combobox แล้วบันทึกข้อมูลลงอีกตารางแล้วerror
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
If Me._condb.connectDB() Then
Me._condb.tr = Me._condb.con.BeginTransaction()
Try
sb.Remove(0, sb.Length)
sb.Append(" Insert into login_user (login_user_employee_id,login_user_title,login_user_name,login_user_lastname,login_user_password,position_id,department_code) ")
sb.Append(" values ('" & Me.EmployeeIdText.Text & "', ")
sb.Append(" '" & Me.UserTitleText.Text & "', ")
sb.Append(" '" & Me.UserNameText.Text & "', ")
sb.Append(" '" & Me.UserLastnameText.Text & "', ")
sb.Append(" '" & Me.UserPasswordText.Text & "', ")
sb.Append(" '" & Me.PositionNameCombo.SelectedValue & "', ") มัน error ตรงนี้ครับ ไม่รู้ว่าจะแก้ยังงัย
sb.Append(" '" & Me.DepartmentNameCombo.SelectedValue & "') ") มัน error ตรงนี้ครับ ไม่รู้ว่าจะแก้ยังงัย
Me._condb.com = New MySqlCommand
Me._condb.com.CommandType = CommandType.Text
Me._condb.com.CommandText = sb.ToString()
Me._condb.com.Connection = Me._condb.con
Me._condb.com.Transaction = Me._condb.tr
Me._condb.com.ExecuteNonQuery()
Me._condb.tr.Commit()
Me.EmployeeIdText.Text = ""
Me.UserTitleText.Text = ""
Me.UserNameText.Text = ""
Me.UserLastnameText.Text = ""
Me.UserPasswordText.Text = ""
Me.PositionNameCombo.SelectedValue = ""
Me.DepartmentNameCombo.SelectedValue = ""
MsgBox("บันทึกข้อมูลสำเร็จ", MsgBoxStyle.Information, "ผลการทำงาน")
Catch ex As Exception
Me._condb.tr.Rollback()
MsgBox("ไม่สามารถ บันทึก ข้อมูลได้ เนื่อง จาก " & ex.Message.ToString(), MsgBoxStyle.Critical, "Error")
End Try
Else
MsgBox("ไม่สามารถ ติดต่อ ฐาน ข้อมูลได้", MsgBoxStyle.Critical, "Error")
End If
End SubTag : .NET, MySQL, VB.NET
Date :
2014-10-20 09:17:00
By :
nankittiphat
View :
1396
Reply :
3
อันนี้โค้ด combobox
Private Sub ShowDataInCombobox1()
Me._condb.connectDB()
sb.Remove(0, sb.Length)
sb.Append(" select * from position ")
Me._condb.da = New MySqlDataAdapter(sb.ToString(), Me._condb.con)
Dim dsUser As New DataSet
Me._condb.da.Fill(dsUser, "position")
PositionNameCombo.DataSource = dsUser.Tables("position")
PositionNameCombo.DisplayMember = "position_name" 'อยากให้แสดงอะไร ?
PositionNameCombo.ValueMember = "position_id" 'เก็บ
End Sub
Private Sub ShowDataInCombobox2()
Me._condb.connectDB()
sb.Remove(0, sb.Length)
sb.Append(" select * from department ")
Me._condb.da = New MySqlDataAdapter(sb.ToString(), Me._condb.con)
Dim dsUser As New DataSet
Me._condb.da.Fill(dsUser, "department")
DepartmentNameCombo.DataSource = dsUser.Tables("department")
DepartmentNameCombo.DisplayMember = "department_name" 'อยากให้แสดงอะไร ?
DepartmentNameCombo.ValueMember = "department_code" 'เก็บ
End Sub
Date :
2014-10-20 09:34:01
By :
nankittiphat
ลอง
sb.Append(" '" & Me.PositionNameCombo.SelectedValue.Tostring() & "', ")
sb.Append(" '" & Me.DepartmentNameCombo.SelectedValue.Tostring() & "') ")
Date :
2014-10-20 14:58:19
By :
gaowteen
ขอบคุณครับผม
Date :
2014-10-21 10:01:50
By :
nankittiphat
Load balance : Server 02