|  | 
	                
  
    |  |  
    | 
        
        ช่วยผมด้วยมีปัญหา   .ExecuteNonQuery()... ExecuteNonQuery requires an open and available Connection. The connection's current state is closed     |  
    |  |  
 
              
  
    | 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้ครับขอบคุณครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-16 18:19:06 | By :
                            kinnon |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุนก้าบ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2013-07-25 09:47:37 | By :
                            rrung |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | สองแง่สองง่ามครับ ล่อแหลมมาก 
 ต้องสั่งเปิดการเชื่อมต่อโดย conn.Open() ก่อน  .ExecuteNonQuery() นะครับ
 
 ที่สำคัญ : เปิด .Open() ให้ถูกตัว ถูกอินสแตนด้วยนะครับ
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2013-07-25 11:28:29 | By :
                            01000010 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label2.Text = Today
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sQL As String
        sQL = "insert into Add(Date,Number,Namebook,Peice)"
        sQL = sQL & "VALUES('"
        sQL = sQL & TextBox1.Text & "','"
        sQL = sQL & TextBox2.Text & "','"
        sQL = sQL & TextBox3.Text & "')"
        Dim cmd As SqlCommand
        cmd = New SqlCommand
        With cmd
            .CommandType = CommandType.Text
            .CommandText = sQL
            .Connection = conn()
            .ExecuteNonQuery()   (มันขึ้น eroor ตรงนี้คับช่วยทีนะคับ)
        End With
        MsgBox("เพิ่มข้อมูลเรียบร้อยแล้ว")
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox2.Clear()
    End Sub
End Class
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2014-03-28 10:48:05 | By :
                            TaTak |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | กรุณาที่ครับผมเพิ่มเรียนยังไม่ค่อยเข้าใจ นี้โค้ดผม
 
 Code (VB.NET)
 
 Private Sub ButtonSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonSave.Click
        If Not (IsNumeric(TextNumFloors.Text) OrElse Is Integer(TextNumFloors.Text)) Then
            MessageBox.Show("จำนวนชั้นต้องเป็นเลขจำนวนเต็ม")
            Exit Sub
        ElseIf Not (IsNumeric(TextRoomsPerFloor.Text) OrElse IsInteger(TextRoomsPerFloor.Text)) Then
            MessageBox.Show("จำนวนห้องในแต่ละชั้นต้องเป็นเลขจำนวนเต็ม")
            Exit Sub
        ElseIf Not IsNumeric(TextNumFloors.Text) Then
            MessageBox.Show("ค่าเช่าต้องเป็นตัวเลข")
            Exit Sub
        End If
        If hasRows Then
            sql = "UPDATA Ref SET " & "NumFloors = @floors, " & "RoomsPerFloor = @rooms, " & "Rental = @rent"
        Else
            sql = "INSERT INTO Ref(NumFloors,RoomsPerFloors,Rental) " & "VALUES(@floors, @rooms, @rent)"
        End If
        command = New SqlCommand(sql, connection)
        command.Parameters.Clear()
        command.Parameters.AddWithValue("floors", TextNumFloors.Text)
        command.Parameters.AddWithValue("rooms", TextRoomsPerFloor.Text)
        command.Parameters.AddWithValue("rent", TextRental.Text)
        Dim r As Integer = command.ExecuteNonQuery()
        If r = 1 Then
            MessageBox.Show("ปรับปรุงข้อมูล")
            connection.Close()
            FormRef_load(sender, e)
        Else
            MessageBox.Show("เกิดข้อผิดพลาด")
        End If
    End Sub
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-09-08 17:03:14 | By :
                            Mekasith |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | กรุณาช่วยที่ครับผมพึ่งเริ่มเรียนยังไม่ค่อยเข้าใจ นี้โค้ดผม
 
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-09-08 17:07:52 | By :
                            Mekasith |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |