|  | 
	                
  
    |  |  
    | 
        
        ช่วยดู code Update อันนี้หน่อยครับ   มันไม่ยอมเปลี่ยนข้อมูลครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | ผมใช้ VB2008  กับ MySQLserver2005 ครับ    ทำโค๊ด Update แล้วข้อมูลมันไม่ยอมเปลี่ยนแปลงหน่ะครับ 
 ตามนี้ครับ   ช่วยดูให้หน่อยนะครับ  เพราะมันคือโปรเจคจบของผมหน่ะครับ
 
 ฃSub Edit_Insert_DB()
 Dim COMPUTER_S_con As String
 If MessageBox.Show("คุณต้องการแก้ไขข้อมูล ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
 Exit Sub
 
 End If
 Try
 COMPUTER_S_con = oComputer_database.COMPUTER_S_con
 
 Conn = New SqlConnection()
 With Conn
 If .State = ConnectionState.Open Then .Close()
 .ConnectionString = COMPUTER_S_con
 .Open()
 
 End With
 
 sb = New StringBuilder()
 
 sb.Remove(0, sb.Length)
 sb.Append("Update dbProduct set ID=@ID,Name=@Name,Price=@Price,Number=@Number")
 sb.Append("where ID='" + txtID.Text + "' ")
 Dim sqlAdd As String
 sqlAdd = sb.ToString()
 com = New SqlCommand()
 With com
 .CommandText = sqlAdd
 .CommandType = CommandType.Text
 .Connection = Conn
 .Transaction = tr
 .Parameters.Clear()
 
 com.Parameters.Add("@ID", SqlDbType.NVarChar).Value = txtID.Text
 com.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtName.Text
 com.Parameters.Add("@Price", SqlDbType.NVarChar).Value = txtSale.Text
 com.Parameters.Add("@Number", SqlDbType.NVarChar).Value = txtNumber.Text
 .ExecuteNonQuery()
 
 End With
 but_OK.Enabled = False
 MessageBox.Show("แก้ไขรายการเรียบร้อยแล้วครับ.", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
 
 Catch
 
 MessageBox.Show(Err.Description, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
 
 End Try
 End Sub
 
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2010-03-26 23:04:34 | By :
                          goburi78 | View :
                          1256 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  Code (VB.NET)
 
 'จาก
sb.Remove(0, sb.Length)
sb.Append("Update dbProduct set ID=@ID,Name=@Name,Price=@Price,Number=@Number")
sb.Append("where ID='" + txtID.Text + "' ")
Dim sqlAdd As String
sqlAdd = sb.ToString()
com = New SqlCommand()
With com
	.CommandText = sqlAdd
	.CommandType = CommandType.Text
	.Connection = Conn
	.Transaction = tr
	.Parameters.Clear()
	
	com.Parameters.Add("@ID", SqlDbType.NVarChar).Value = txtID.Text
	com.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtName.Text
	com.Parameters.Add("@Price", SqlDbType.NVarChar).Value = txtSale.Text
	com.Parameters.Add("@Number", SqlDbType.NVarChar).Value = txtNumber.Text
	.ExecuteNonQuery()
End With
 Code (VB.NET)
 
 'แก้เป็น
sb.Clear()
sb.AppendLine("Update dbProduct set ID=@ID,Name=@Name,Price=@Price,Number=@Number")
sb.AppendLine("where  ID=@ID ")
Dim sqlAdd As String
sqlAdd = sb.ToString()
com = New SqlCommand()
With com
	.CommandText = sqlAdd
	.CommandType = CommandType.Text
	.Connection = Conn
	.Transaction = tr
	.Parameters.Clear()
	
	com.Parameters.AddWithValue("@ID", txtID.Text.Trim())
	com.Parameters.AddWithValue("@Name", txtName.Text.Trim())
	com.Parameters.AddWithValue("@Price",  CCurr( txtSale.Text.Trim()))
	com.Parameters.AddWithValue("@Number",  CInt(txtNumber.Text.Trim()))
	.ExecuteNonQuery()
End With
 สาเหตุ น่าจะเกิดจากการเชื่อม sqlcommand ด้วย Append ทำให้ไม่มี space คั่นก่อนหน้า Where
 และที่ txtSale และ txtNumber แน่ใจหรอคะว่าเป็นตัวเลขมีการตรวจสอบหรือยัง
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-03-27 14:28:30 | By :
                            blurEye |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (VB.NET) 
 sb.AppendLine("where  ID=@ID ") 'น่าจะเป็นตรงที่ ("where  ID=@ID ") ลอง Specbar ให้ where
'ห่างจาก String ดูน่ะครับ ("  where  ID=@ID ")
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-03-27 14:47:27 | By :
                            EvolutionGT |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อ้าว หรอคะ ขอโทษค่ะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-03-27 21:47:56 | By :
                            blurEye |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |