HOME > .NET Framework > Forum > มันError ช่วยแก้ให้หน่อยนะค่ะ ใกล้จะส่งแล้ว มันขึ้น Error ว่า Error ว่า ExecuteReader: CommandText property has not been initialized
มันError ช่วยแก้ให้หน่อยนะค่ะ ใกล้จะส่งแล้ว มันขึ้น Error ว่า Error ว่า ExecuteReader: CommandText property has not been initialized
มันขึ้น Error ว่า ExecuteReader: CommandText property has not been initialized ช่วยดูให้หน่อยนะค่ะ ขอบคุณล่วงหน้าค่ะ
Code (VB.NET)
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
'Dim sqlCustomers As String = ""
'sqlCustomers = "select * from Customers Where AdmitDate=@AdmitDate"
'If IsFind = True Then
' ds.Tables("Customers").Clear()
'End If
'da = New SqlDataAdapter(sqlCustomers, Conn)
'da.Fill(ds, "Customers")
'If ds.Tables("Customers").Rows.Count <> 0 Then
' IsFind = True
' calculatenetCustomer()
'Else
' IsFind = False
' MessageBox.Show("ไม่มีเวลาที่ระบุ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
' lblTotal.Text = "0"
'End If
'FormatlsvCustomer()
Dim DetailType As String
sb.Remove(0, sb.Length)
sb.Append("Select customerID,FullName,AdmitDate,Paid")
sb.Append("From Customers")
sb.Append("Where (AdmitDate Between '" & dtpStart.Value.ToString("d", dtfinfo) & "'")
sb.Append("And '" & dtpEnd.Value.ToString("d", dtfinfo) & "')")
sb.Append(" And (BranchName=@BranchName)")
sb.Append("Order By AdmitDate DESC")
DetailType = "Customers"
Dim sqldata As String
sqldata = sb.ToString
btnCheck.Enabled = False
bgwCheck.RunWorkerAsync()
End Sub
Private Sub bgwCheck_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwCheck.DoWork
Dim comCheck As SqlCommand
comCheck = New SqlCommand
Dim drCheck As SqlDataReader
Dim dtCheck As DataTable
Dim CheckResult As Integer
With comCheck
.Parameters.Clear()
.Parameters.Add("@BranchName", SqlDbType.NVarChar).Value = cboBranch
.CommandText = sqldata
.Connection = Conn
drCheck = .ExecuteReader
dtCheck = New DataTable
If drCheck.HasRows Then
dtCheck.Load(drCheck)
CheckResult = dtCheck.Rows.Count
Else
CheckResult = 0
End If
drCheck.Close()
End With
End Sub
Private Sub bgwCheck_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwCheck.RunWorkerCompleted
Dim CheckResult As Integer
'Dim drCheck As SqlDataReader
If CheckResult = 0 Then
ClearAllData()
MessageBox.Show("เงื่อนไขที่คุณป้อน ไม่มี !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
btnReport.Enabled = True
'lsvCustomer = drCheck
lblCheck.Text = "พบ : " & CheckResult.ToString() & " รายการ"
FormatlsvCustomer()
calculatenetCustomer()
End If
btnCheck.Enabled = True
End Sub