รัน Project แล้ววมีข้อความแจ้งเตือนว่า " Error Conversion from String" INSERT INTO B_User(Log_User,Log_" to type integer not valid หาข้อผิดพลาดไม่เจอคะ รบกวนแนะนำด้วยนะคะ
Code (VB.NET)
Private Sub Wprv_SaveData(ByVal _sAction As String)
Dim sSql As String = ""
If txtUsername.Text.Trim = "" Then
MessageBox.Show("กรุณากรอก Username ", "ตรวจสอบ", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Exit Sub
End If
If txtPassword.Text.Trim = "" Then
MessageBox.Show("กรุณากรอก Password ", "ตรวจสอบ", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Exit Sub
End If
If _sAction.ToUpper = "ADD" Then
sSql = "INSERT INTO B_User(Log_User,Log_Pass) VALUES " _
& "(' " & txtUsername.Text.Trim & "','" & txtPassword.Text.Trim & "')"
Public Sub Cpuv_ConDataBase(ByVal _sDataBase As String,
ByVal _nCBase As Integer, ByVal _sServerName As String,
ByVal _sUsername As String, ByVal _sPassword As String)
Dim sConn As String = ""
Try
bCheckConnect = False
Select Case _nCBase
Case 2
'Sql Server
sConn = " Provider=sqloledb;data source =" & _sServerName & ";initial catalog=" &
_sDataBase & ";user id=" & _sUsername & ";password=" & _sPassword & ";"
End Select
With polecon
If .State = ConnectionState.Open Then .Close()
.ConnectionString = sConn
.Open()
End With
bCheckConnect = True
Catch ex As Exception
MessageBox.Show("ไม่สามารถติดต่อฐานข้อมูลได้เพราะ " & ex.Message.ToString(), "ตรวจสอบ" _
, MessageBoxButtons.OK, MessageBoxIcon.Error)
bCheckConnect = False
End Try
poleConAc = New System.Data.OleDb.OleDbConnection(sConn)
End Sub
[font=Verdana]Code ที่ปุ่ม Add[/font]
Private Sub Wprv_SaveData(ByVal _sAction As String)
Dim sSql As String = ""
If txtUsername.Text.Trim = "" Then
MessageBox.Show("กรุณากรอก Username ", "ตรวจสอบ", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Exit Sub
End If
If txtPassword.Text.Trim = "" Then
MessageBox.Show("กรุณากรอก Password ", "ตรวจสอบ", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Exit Sub
End If
If _sAction.ToUpper = "ADD" Then
sSql = "INSERT INTO B_User(Log_User,Log_Pass) VALUES" _
& "('" & txtUsername.Text.Trim & "','" & txtPassword.Text.Trim & "')"
ElseIf _sAction.ToUpper = "EDIT" Then
If (MessageBox.Show("คุณต้องการแก้ไขข้อมูล ใช่หรือไม่", "ตรวจสอบ", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) _
= Windows.Forms.DialogResult.No) Then
Exit Sub
End If
ElseIf _sAction.ToUpper = "DELETE" Then
If (MessageBox.Show("คุณต้องการลบข้อมูล ใช่หรือไม่", "ตรวจสอบ", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) _
= Windows.Forms.DialogResult.No) Then
Exit Sub
End If
If txtUsername.Text.Trim = psUsername Then
MessageBox.Show("ไม่สามารถลบข้อมูลนี้ได้", "ตรวจสอบ", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Exit Sub
End If
sSql = " Delete From B_User Where log_User='" & txtUsername.Text.Trim & "' And " _
& " Log_Pass='" & txtPassword.Text.Trim & "'"
End If
If Cpub_ActionData(sSql) = True Then
MessageBox.Show("เรียบร้อยแล้ว", "ตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Wprv_ShowData()
End If
End Sub
Private Sub FrmUser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Wprv_ShowData()
End Sub
Private Sub cmdEdit_Click(sender As Object, e As EventArgs) Handles cmdEdit.Click
Wprv_SaveData("EDIT")
End Sub
Private Sub cmdDelete_Click(sender As Object, e As EventArgs) Handles cmdDelete.Click
Wprv_SaveData("DELETE")
End Sub
Private Sub cmdClear_Click(sender As Object, e As EventArgs) Handles cmdClear.Click
Wprv_Clear()
End Sub
Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
Wprv_SaveData("ADD")
End Sub
Private Sub cmdClose_Click(sender As Object, e As EventArgs) Handles cmdClose.Click
Me.Close()
End Sub
Private Sub lsvShowData_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lsvShowData.MouseDoubleClick
If lsvShowData.SelectedItems.Count <> 0 Then
txtUsername.Text = lsvShowData.SelectedItems.Item(0).SubItems(0).Text
txtPassword.Text = lsvShowData.SelectedItems.Item(0).SubItems(1).Text
Wprv_Lock(False)
End If
End Sub
End Class