 |
|
[asp.net]#vb Update SQL แล้ว ไม่อัพเดต ครับ แต่ไม่มี error ใดๆ |
|
 |
|
|
 |
 |
|
[asp.net]#vb Update SQL แล้ว ไม่อัพเดต ครับ แต่ไม่มี error ใดๆ
ผมทำ หน้า แก้ไขข้อมูลสมาชิกครับ
เมื่อสมาชิก กดเข้ามา จะโชว์ข้อมูล จากSQL Server ใน Textbox
แล้ว สามารถแก้ไข ได้ พอกด save ก็บันทึก
แต่พอกด save แล้ว ข้อมูลไม่อัพเดต ครับ
*ข้อมูลของ user มาโชว์บน textbox แล้วครับ
Code ทำให้ ข้อมูลของ user มาโชว์ที่ textbox
Dim strConnection As String = "Data Source=DELL_BLUE-PC;Initial Catalog=Test;Integrated Security=True"
Dim Connection As New SqlConnection(strConnection)
Dim strCommand As String = "Select [Username], [Name], [LastName], [Email], [Address] From [Member] Where [UserID]=@UserID"
Dim Command As New SqlCommand(strCommand, Connection)
Command.Parameters.AddWithValue("@UserID", CInt(Session("UserID")))
Try
Connection.Open()
Dim dataReader As SqlDataReader = Command.ExecuteReader(CommandBehavior.SingleRow)
dataReader.Read()
txtusername.Text = dataReader("UserName").ToString()
txtname.Text = dataReader("Name").ToString()
txtlname.Text = dataReader("LastName").ToString()
txtemail.Text = dataReader("Email").ToString()
txtaddress.Text = dataReader("Address").ToString()
dataReader.Close()
Connection.Close()
Catch ex As Exception
MessageBox.Show(String.Format("Error: {0}", ex.Message))
End Try
lblwel.Text = String.Format("Welcome {0}", txtusername.Text)
End If
อันนี้ Code ปุ่ม save
Dim strConnection As String = "Data Source=DELL_BLUE-PC;Initial Catalog=Test;Integrated Security=True"
Dim Connection As New SqlConnection(strConnection)
Dim strCommand As String = "Update [Member] Set [Name]=@Name ,[LastName]=@LastName ,[Email]=@Email ,[Address]=@Address Where [UserID]=@UserID"
Dim Command As New SqlCommand(strCommand, Connection)
Command.Parameters.AddWithValue("@Name", txtname.Text)
Command.Parameters.AddWithValue("@LastName", txtlname.Text)
Command.Parameters.AddWithValue("@Email", txtemail.Text)
Command.Parameters.AddWithValue("@Address", txtaddress.Text)
Command.Parameters.AddWithValue("@UserID", CInt(Session("UserID")))
Try
Connection.Open()
Command.ExecuteNonQuery()
Connection.Close()
MessageBox.Show("อัฟเดตข้อมูลเรียบร้อย")
Catch ex As Exception
MessageBox.Show(String.Format("Error: {0}", ex.Message))
End Try
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET
|
|
 |
 |
 |
 |
Date :
2010-10-25 15:32:32 |
By :
Help Me |
View :
2325 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Response.Write("Found Error in edit Aww <br>" & ex.ToString)
ลองแบบนี้ดูนะครับ
|
 |
 |
 |
 |
Date :
2010-10-25 15:59:22 |
By :
e_dong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Session("UserID") ID มีค่าครับ
ผมลอง ให้ ใช้ Label = Session("UserID") ดู มันก็ขึ้น ตัวเลข ครับ
|
 |
 |
 |
 |
Date :
2010-10-25 16:10:05 |
By :
Help Me |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สำหรับ
Response.Write("Found Error in edit Aww <br>" & ex.ToString)
ลองแบบนี้ดูนะครับ
มันไม่เข้า กรณี Catch ex As Exception อ่ะครับ เหมือน มันขึ้น ข้อความ อัฟเดตข้อมูลเรียบร้อย
เหมอืนกับ ว่าไม่ผิดพลาด แต่ไม่ อัพเดต
|
 |
 |
 |
 |
Date :
2010-10-25 16:12:35 |
By :
Help Me |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งง ครับ ไม่ทราบผิดตรงไหน
อันเก่า แก้ password แก้ได้นะ ครับ ก็ เอา code มาจากอันเก่า
แต่พอกด ไม่อัพเดต
|
 |
 |
 |
 |
Date :
2010-10-25 22:09:16 |
By :
Help Me |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเช็คดู security ของ database
|
 |
 |
 |
 |
Date :
2010-10-26 10:50:02 |
By :
e_dong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
security ของ database ไม่น่าเกี่ยวนะครับ เพราะ update Password ใช้การได้
[headอันนี้ Code ต้นแบบ เปลี่ยน PAssword ใช้การได้ครับ อัพเดตได้[/head]
Dim strConnection As String = "Data Source=DELL_BLUE-PC;Initial Catalog=Test;Integrated Security=True"
Dim Connection As New SqlConnection(strConnection)
Dim strCommand As String = "Update [Member] Set [UserPassword]=@UserPassword Where [UserID]=@UserID"
Dim Command As New SqlCommand(strCommand, Connection)
Command.Parameters.AddWithValue("@UserPassword", passwordTextBox.Text)
Command.Parameters.AddWithValue("@UserID", CInt(Session("UserID")))
Try
Connection.Open()
Command.ExecuteNonQuery()
Connection.Close()
MessageBox.Show("อัฟเดตข้อมูลเรียบร้อย")
Catch ex As Exception
MessageBox.Show(String.Format("Error: {0}", ex.Message))
End Try
Response.Redirect("~/Home/Home.aspx")
|
 |
 |
 |
 |
Date :
2010-10-26 12:38:52 |
By :
Help Me |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นที่ ขั้นตอน การดึงข้อมูล จาก SQL SErver มาแสดงใน Textbox ไหมครับ
เพราะ code แก้ไข Password ไม่มีการ ดึงข้อมูลจาก textbox มาโชวืแล้วทำการแก้ไข
แต่ ใส่ pass แก้ไขเลย
ช่วยหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2010-10-26 13:58:47 |
By :
HelpMe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนดึงข้อมูลมา show ใน txtbox
ให้ใส่
If Not Page.IspostBack then
txtname.text = ...
txtsurname.text = ...
end if
เพราะไมงั้นมันจะไม่ update ให้เนื่องจาก ตอนกด save มันจะทำ even page_load ก่อน
ทำค่าที่ update ได้ข้อมูลเดิม
เป้นคำตอบสุดท้ายครับ
|
 |
 |
 |
 |
Date :
2010-10-26 14:36:42 |
By :
superpheak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป้นคำตอบสุดท้ายครับ
ขอบคุณมากครับบบ ผม ซึ้งเลย สำเร็จแล้ว
|
 |
 |
 |
 |
Date :
2010-10-26 14:41:25 |
By :
HelpMe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับหาตั้งนาน 
|
 |
 |
 |
 |
Date :
2011-01-04 03:53:57 |
By :
fidoddo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุนสำหรับข้อมูล
แทบร้องแน่ะกำลังติดตรงนี้อยู่พอนี้มีประโยชน์จิงๆได้บอดนี้ช่วยหลายครั้งแล้ว
|
 |
 |
 |
 |
Date :
2011-01-16 00:48:47 |
By :
thank |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ โดนมากกกกก
|
 |
 |
 |
 |
Date :
2012-02-12 19:39:59 |
By :
cty |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|