ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. แก้ไงหรอคับมือใหม่เจอบัคงี้ งงกวนช่วยทีคับ
Code (VB.NET)
Private Sub FSave()
'Try
Conn = New OleDbConnection(strConnString)
Conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * From TB_Book", Conn)
Dim adp As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim dataset As DataSet = New DataSet
Dim sql As String
'Select Case flag
'Case 0
'Getmax()
sql = "INSERT INTO [TB_Book](Book_Name,Book_Detail,Book_Cost,Book_Quantity,Book_Rent,Book_Publisher,Book_Date,Book_Penalty) Values('" & txtBook.Text & "','" & txtdetail.Text & "','" & txtPrice.Text & "','" & txtStock.Text & "','" & txtRent.Text & "','" & txtPub.Text & "','" & txtDate.Text & "','" & txtPenalty.Text & "')"
cmd = New OleDbCommand(sql, Conn)
cmd.ExecuteNonQuery()
Conn.Close()
Dim response As DialogResult = MessageBox.Show("บันทึกเสร็จสมบูรณ์", "บันทึกข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
Cleartxt()
FShow()
'Case 1
sql = "Update [TB_Book] Set Book_Name='" & txtBook.Text & "',Book_Detail='" & txtdetail.Text & "',Book_Cost='" & txtPrice.Text & "',Book_Quantity='" & txtStock.Text & "',Book_Rent='" & txtRent.Text & "',Book_Publisher='" & txtPub.Text & "',Book_Date='" & txtDate.Text & "',Book_Penalty='" & txtPenalty.Text & "' where Book_ID='" & txtcodebook.Text & "'"
cmd = New OleDbCommand(sql, Conn)
cmd.ExecuteNonQuery()
Conn.Close()
Dim result As DialogResult = MessageBox.Show("แก้ไขเสร็จสมบูรณ์", "แก้ไขข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
Cleartxt()
FShow()
Tag : ASP.NET, Ms SQL Server 2005, Ms SQL Server 2008, VB.NET
Date :
2011-12-17 18:22:08
By :
n_Plus
View :
1266
Reply :
1
คุณไป Close Connect แล้วก็ไปเรียกใช้มันอีกทีน่ะครับ มันเลย Error ตรง Link 17
Date :
2011-12-17 22:14:21
By :
webmaster
Load balance : Server 04