Private Sub UC_Patient_UseDrug_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowSelectDate()
formatGrid()
End Sub
Public Sub ShowSelectDate()
SelDate = SelectDate.Value.ToString("yyyy/MM/dd")
Dim DSel As Date = SelDate
Dim myformat() As String = {"yyyy-MM-dd"}
Dim i As Integer
For i = 0 To myformat.Length - 1
SelDate = DSel.ToString(myformat(i), DateTimeFormatInfo.InvariantInfo)
Next i
ds.Clear()
ds = clsP.ShowSelAll(SelDate)
ConnS.Open()
DataGridName.DataSource = ds.Tables(0)
ConnS.Close()
End Sub
Public Sub formatGrid()
With DataGridName
.Columns(0).HeaderText = "ชื่อผู้ป่วย"
.Columns(0).Width = 300
End With
End Sub
Tag : .NET, Ms SQL Server 2012, VS 2012 (.NET 4.x), Windows
SELECT dbo.Prescription.PatientName FROM dbo.Prescription
WHERE (dbo.Prescription.PrescriptionDate = '2013-07-17')
GROUP BY dbo.Prescription.PatientName
ORDER BY dbo.Prescription.PatientName ASC
Public Function Fill(ByVal cmd As SqlCommand) As DataSet
Try
cmd.Connection = New SqlConnection(JSDThon)
cmd.Connection.Open()
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
If Not ds Is Nothing Then ds.Clear()
da.Fill(ds)
Return ds
End Using
Catch ex As Exception
WriteLog(ex.ToString, "ERROR")
Return Nothing
Finally
cmd.Connection.Close()
cmd.Connection.Dispose()
End Try
End Function
[21/10/2013 09:21:12] System.InvalidOperationException: The ConnectionString property has not been initialized.
at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Plan.Module1.Fill(SqlCommand cmd) in D:\Work_Nid\Plan\Plan\Plan\Module1.vb:line 31
Public Function Fill(ByVal cmd As SqlCommand) As DataSet
Try
cmd.Connection = New SqlConnection(JSDThon)
cmd.Connection.Open()
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
If Not ds Is Nothing Then ds.Clear()
da.Fill(ds)
Return ds
End Using
Catch ex As Exception
'WriteLog(ex.ToString, "ERROR")
'Return Nothing
msgbox(JSDThon.ConnectionString)
msgbox(cmd.Connection.ConnectionString) 'ผมมั่วเอาน่ะครับ แก้ให้ด้วย
msgbox(ex.Message)
Finally
cmd.Connection.Close()
cmd.Connection.Dispose()
End Try
End Function