 |
|
กดรันแล้ว Error Conversion From String" INSERT INTO ......." To Type integer is not Valid รบกวนหาข้อผิดพลาดให้หน่อยคะ |
|
 |
|
|
 |
 |
|
รัน 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 & "')"
Tag : .NET, VB.NET, VS 2017 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2018-11-24 19:44:35 |
By :
Paenoi789 |
View :
1338 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่ค่าให้เป็น integer
|
 |
 |
 |
 |
Date :
2018-11-24 22:01:24 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนสอบถามเพิ่มเติมนะคะ ต้องใส่ค่าให้เป็น integer ตรงไลน์ไหนคะ
|
 |
 |
 |
 |
Date :
2018-11-24 22:34:34 |
By :
Paenoi789 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนแก้ไข Code ช่วยหน่อยคะ หาข้อผิดพลาดไม่เจอคะ เวลาใส่ Username กับ Password แล้วกดปุ่ม เพิ่ม มันโชว์ Error รบกวนด้วยนะคะ พอดีฝึกเขียนตาม YouTobe พื้นฐานมีน้อยนิดคะ วัตถุประสงค์เพื่อจะใช้ในการอำนวยความในการทำงานนะค่ะ


Code (VB.NET)
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
sSql = " Update B_User Set Log_Pass='" & txtPassword.Text.Trim & " ' Where " _
& " Log_User='" & txtUsername.Text.Trim & "'"
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
|
 |
 |
 |
 |
Date :
2018-11-25 09:07:15 |
By :
Paenoi789 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
error ไม่ใช่โค้ดโดยตรง แต่เป็นเรื่องความเข้าใจ datatype
แนะนำให้อ่าน เรื่อง datatype ให้เข้าใจก่อนดีกว่าไม๊ครับ
พอเข้าใจ เรื่อง datatype เราจะไม่มีข้อผิดพลาด แบบนี้ หรือ ทำนองนี้อีกเลย
ถ้ารู้เรื่อง datatype คร้าน แต่จะร้องอ๋อ นั่งแก้โค้ด ไปอีก 3 วัน ถ้าไม่รู้ datatype ก็จะต้องมานั่งอีกเรื่อยๆ
เพราะยังมีอีกหลายตัวนะครับที่จะมีปัญหา สำหรับคนที่ไม่รู้เรื่อง datatype
|
 |
 |
 |
 |
Date :
2018-11-25 18:44:48 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคำแนะนำนะคะ
|
 |
 |
 |
 |
Date :
2018-12-03 16:50:15 |
By :
Paenoi789 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|