 |
|
ช่วยดู Syntax error in UPDATE statement. ของ Login Form ทีครับ |
|
 |
|
|
 |
 |
|

ช่วยดู Code เปลี่ยนรหัสผ่านของ user_login ให้ทีครับ ผมติด Error Syntax Update ครับ ยังไงช่วยทีครับ ขอบคุณล่วงหน้าครับ
___________________________________________________________________________________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_conn = New OleDbConnection(_conStr)
_conn.Open()
Dim sqlSave As String
Dim sql As String
sql = "select * from User_Login WHERE user_id ='" & TextBox1.Text & "'" & _
"AND password = '" & TextBox2.Text & "'"
Dim _cmd As New OleDbCommand(sql, _conn)
_dataset = New DataSet()
Dim _adapter As New OleDbDataAdapter(_cmd)
_adapter.Fill(_dataset, "login")
If _dataset.Tables("login").Rows.Count <= 0 Then
MessageBox.Show("User ID and Password ผิดพลาด", "กรุณาตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TextBox1.SelectAll()
Else
If TextBox3.Text = TextBox4.Text Then
sql.Remove(0, sql.Length)
sql = "UPDATE User_Login SET user_id = @id, password = @pass WHERE user_id = @id"
sqlSave = sql.ToString
_cmd = New OleDbCommand(sql, _conn)
With _conn
_cmd.CommandText = sqlSave
_cmd.CommandType = CommandType.Text
_cmd.Parameters.Clear()
_cmd.Parameters.Add("id", OleDbType.Char).Value = TextBox1.Text
_cmd.Parameters.Add("pass", OleDbType.Char).Value = TextBox3.Text
_cmd.ExecuteNonQuery()
End With
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Else
MessageBox.Show("กรุณาตรวจสอบ Password ใหม่อีกครั้งคะ")
TextBox3.SelectAll()
End If
End If
_conn.Close()
End Sub
Tag : .NET, Ms Access, VB.NET
|
|
 |
 |
 |
 |
Date :
2011-01-29 18:33:19 |
By :
iSOON_zA |
View :
1435 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
UPDATE User_Login SET password = @pass WHERE user_id = @id
จะเปลี่ยนรหัสเเล้วจะอัพเดท ID ทำไมเหรอครับ
|
ประวัติการแก้ไข 2011-01-29 23:06:58
 |
 |
 |
 |
Date :
2011-01-29 23:06:03 |
By :
EucifeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองใส่ Update User_Login Set password = @pass Where user_id = @id ของทั้ง 2 แบบล่ะครับ ก็ยัง Error เหมือนเดิมอ่ะครับ
เพิ่มเติมนิดหน่อยครับ _conn = New OleDbConnection(_conStr) <----- _conStr ผมประกาศตัวแปรติดต่อฐานข้อมูลAccess ไว้ที่ โมดูลแล้วน่ะครับ
ฟอร์มอื่น ๆ ผมก็แก้ไข Update ได้ครับ แต่มา ฟอร์มนี้ ติด Error ซะงั้น !!!! ยังไงก็ขอคำแนะนำด้วยน่ะครับ (ผมพึ่งหัดเขียน)
|
 |
 |
 |
 |
Date :
2011-01-29 23:21:25 |
By :
iSOON_zA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sql = "select * from User_Login WHERE user_id ='" & TextBox1.Text & "'" & _
"เคาะตรงนี้ครับ มันติดกันAND password = '" & TextBox2.Text & "'"
|
 |
 |
 |
 |
Date :
2011-01-30 00:17:47 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
sql = "select * from User_Login WHERE user_id ='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
อย่างนี้อะป่าว
|
 |
 |
 |
 |
Date :
2011-01-30 00:51:44 |
By :
EucifeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเอา &_ ออก เอามาต่อกัน
sql = "select * from User_Login WHERE user_id ='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
ก็ยังเหมือนเดิมครับ ไม่รู้ มัน Error เพราะอะไร เดียวจะลองเอา Code ทั้งฟอร์มมาให้ดูครับ
|
 |
 |
 |
 |
Date :
2011-01-30 00:57:50 |
By :
iSOON_zA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Public Class frmLogin
Private _dataset As DataSet
Private _conn As OleDbConnection
Private _conn1 As OleDbConnection
Private _cmd As OleDbCommand
Private _cmd1 As OleDbCommand
Private _adapter As OleDbDataAdapter
Dim ChangePass As Boolean = False
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
_conn = New OleDbConnection(_conStr)
_conn.Open()
Dim sql As String
sql = "select * from User_Login WHERE user_id ='" & txtUsername.Text & "'" & _
"AND password = '" & txtPassword.Text & "'"
Dim _cmd As New OleDbCommand(sql, _conn)
_dataset = New DataSet()
Dim _adapter As New OleDbDataAdapter(_cmd)
_adapter.Fill(_dataset, "login")
If _dataset.Tables("login").Rows.Count <= 0 Then
MessageBox.Show("User ID and Password ผิดพลาด", "กรุณาตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUsername.Text = Nothing
txtPassword.Text = Nothing
focustext()
Else
frmMain.Show()
Me.Hide()
End If
_conn.Close()
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Me.Close()
End Sub
Private Sub focustext()
txtUsername.Focus()
txtUsername.SelectAll()
End Sub
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Height = 292
End Sub
Private Sub cmdChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChange.Click
ChangePass = Not ChangePass
If ChangePass = True Then
Me.Height = 535
Me.Width = 400
TextBox1.Focus()
Panel1.Visible = False
Else
Me.Height = 292
Me.Width = 616
Panel1.Visible = True
txtUsername.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_conn = New OleDbConnection(_conStr)
_conn.Open()
Dim sqlSave As String
Dim sql As String
sql = "select * from User_Login WHERE user_id ='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
Dim _cmd As New OleDbCommand(sql, _conn)
_dataset = New DataSet()
Dim _adapter As New OleDbDataAdapter(_cmd)
_adapter.Fill(_dataset, "login")
If _dataset.Tables("login").Rows.Count <= 0 Then
MessageBox.Show("User ID and Password ผิดพลาด", "กรุณาตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TextBox1.SelectAll()
Else
If TextBox3.Text = TextBox4.Text Then
sql.Remove(0, sql.Length)
sql = "UPDATE User_Login SET password = @pass WHERE user_id = @id"
sqlSave = sql.ToString
_cmd = New OleDbCommand(sql, _conn)
With _conn
_cmd.CommandText = sqlSave
_cmd.CommandType = CommandType.Text
_cmd.Parameters.Clear()
_cmd.Parameters.Add("id", OleDbType.Char).Value = TextBox1.Text
_cmd.Parameters.Add("pass", OleDbType.Char).Value = TextBox3.Text
_cmd.ExecuteNonQuery()
End With
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Else
MessageBox.Show("กรุณาตรวจสอบ Password ใหม่อีกครั้งคะ")
TextBox3.SelectAll()
End If
End If
_conn.Close()
End Sub
End Class
|
 |
 |
 |
 |
Date :
2011-01-30 01:04:13 |
By :
iSOON_zA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Try
Dim sql As String
sql = "SELECT * FROM User_Login WHERE user_id = '" & TextBox1.Text & "'AND password = '" & TextBox2.Text & "'"
Dim dr As OleDbDataReader
Dim com As OleDbCommand
com = New OleDbCommand()
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
.Parameters.Clear()
dr = .ExecuteReader()
If dr.HasRows Then
MessageBox.Show("User ID and Password ผิดพลาด", "กรุณาตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TextBox1.SelectAll()
Else
If TextBox3.Text = TextBox4.Text Then
dim sql as string
sql = "UPDATE User_Login SET password = '" & TextBox3.Text & "' WHERE user_id = '" & TextBox1.Text & "'"
dim dc as New OleDbCommand(sql, _conn)
_cmd.ExecuteNonQuery()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Else
MessageBox.Show("กรุณาตรวจสอบ Password ใหม่อีกครั้งคะ")
End If
End If
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "การตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
ลอง ชุดนี้ดูนะครับ
|
 |
 |
 |
 |
Date :
2011-01-30 01:10:22 |
By :
EucifeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยัง Error เหมือนเดิมเลยครับท่าน มันไปติด Error ตรง _cmd.ExecuteNonQuery() <------ หรือว่าตรงนี้ ผมต้องประกาศไรเพิ่มไหมครับ
ยัง งง ๆ อยู่ครับ ฟอร์ม อื่น ๆ ผมก็ Update ได้ แต่มาฟอร์มนี้ ผมกลับ Update ไม่ได้ แต่ Code ของปุ่มล็อกอิน มันก็ ล็อกอินเข้าได้น่ะครับ
ยังไงก็ต้องขอบคุณคำแนะนำต่าง ๆ ของพวกท่าน ๆ ครับ เดียวจะลองแก้ดูอีกที : )
|
 |
 |
 |
 |
Date :
2011-01-30 11:56:50 |
By :
iSOON_zA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขได้แล้วครับ เส้นผมบังภูเขาจิง ๆ ครับ ผมดันไปใช้คำสงวน ใช้ คำว่า password ลองเปลี่ยน เปลี่ยน user_password ทีนี้ แก้ไข Update ได้ เลย : )
ยังไง ก็ต้องขอขอบคุณ พวกพี่ ๆ ทุก ๆ ท่าน ที่ช่วยให้คำแนะนำต่าง ๆ น่ะครับ . . . เดียวไว้มีปัญหาจะขอมาให้คำแนะนำใหม่ ๆ ครับ ขอบคุณ มา ณ ที่นี้ด้วยครับ . . . . อีกอย่างขอขอบคุณ เว็ปไซค์ thaicreate ครับ ที่ให้ใช้พื้นที่ ให้คำปรึกษา ดี ๆ แบบนี้ ขอบคุณมากครับ ^___^
|
 |
 |
 |
 |
Date :
2011-01-30 14:28:14 |
By :
iSOON_zA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|