ผมต้องการ query ข้อมูลลง SQL Server ครับ
แล้วทีนี้ติด debug ว่า Conversion failed when converting date and/or time from character string. ครับ
ข้อมูลในส่วน เวลาและวันที่ครับ ที่ยังข้อมูลยังไม่ถูก query รบกวนช่วยแก้โคด หรือบอกแนวทางให้หน่อยครับ ติดปัญหาตรงนี้หลายวันแล้วครับ ขอบคุณครับ
Code (VB.NET)
Public Sub SetLabel1Text(ByVal TextToDisplay As String)
Dim d As Date
Dim t As Date
d = Date.Today.Date
d = Format(Now(), "yyyy-MM-dd")
t = Format(Now(), "HH:mm:ss")
If Not (TextToDisplay.ToString().IndexOf("11") = -1) Then
If GroupBox2.InvokeRequired Then
GroupBox2.Invoke(New SetLabel1TextInvoker(AddressOf SetLabel1Text), New Object() {TextToDisplay})
ElseIf Not (TextToDisplay.ToString().IndexOf("1101") = -1) Then
GroupBox2.BackColor = Color.Red
Dim Sql As String = "INSERT INTO Info (sencer_name,status,date,time) VALUES ('A1','ไม่ว่าง','d','t')"
Dim cmd As New SqlCommand(Sql, sqlcon)
cmd.ExecuteNonQuery()
ElseIf Not (TextToDisplay.ToString().IndexOf("1100") = -1) Then
GroupBox2.BackColor = Color.Green
End If
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim DateA As String
Dim DateB As String
Dim USCulture As New System.Globalization.CultureInfo("en-US", True)
DateA = DateTimePicker1.Value.ToString("yyyy-MM-dd", USCulture)
DateB = DateTimePicker2.Value.ToString("yyyy-MM-dd", USCulture)
Dim strSQL As String =
"SELECT * from Info where date '" & DateA & "' AND '" & DateB & "'"
Dim da As New SqlDataAdapter(strSQL, sqlcon)
Dim dt As New DataSet
da.Fill(dt)
DataGridView1.DataSource = dt
sqlcon.Close()
End Sub
Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load
sqlcon = New SqlConnection("Data Source=DELL\SQL2014;Initial Catalog=FSPSDB;Integrated Security=True")
sqlcon.Open()
End Sub
End Class
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim DateA As String
Dim DateB As String
DateA = DateTimePicker1.Value.ToString("yyyy-MM-dd")
DateB = DateTimePicker2.Value.ToString("yyyy-MM-dd")
Dim strSQL As String = "SELECT * from Info where date between '" & DateA & "' And '" & DateB & "'"
MsgBox(strSQL)
Dim da As New SqlDataAdapter(strSQL, sqlcon)
Dim dt As New DataTable
DataGridView1.DataSource = dt
da.Fill(dt)
sqlcon.Close()
End Sub