 |
|
|
 |
 |
|
ลองเช็ค ค่าใน primary key ว่าข้อมูลซ้ำกับที่จะ add ไหม
ปล. มั่วๆ นะ
|
 |
 |
 |
 |
Date :
2010-05-26 14:05:16 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือว่า เขียนsql ดึงข้อมูลมาแสดงในกริดวิว เฉยๆอ่ะคะ ไม่เข้าใจเหมือนกันว่าทำไมไม่ขึ้น มีjoin 2ตารางเอง
|
 |
 |
 |
 |
Date :
2010-05-26 14:07:47 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อย่าลืม ปิด ก่อนนะครับ ก่อน ที่จะ สั่งเปิด connection อีกครัง
เช่น หลังจากได้ ข้อมูลจาก data base มาแล้ว ต้องปิด data reader นะครับ
Code (VB.NET)
01. Dim objConn As System.Data.OleDb.OleDbConnection
02. Dim objCmd As System.Data.OleDb.OleDbCommand
03. Dim strConnString As String
04. strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &Server.MapPath( "database/mydatabase.mdb" )& ";Jet OLEDB:Database Password=;"
05. objConn = New System.Data.OleDb.OleDbConnection(strConnString)
06. objConn.Open()
07. Dim strSQL As String
08. strSQL = "SELECT * FROM customer"
09. Dim dtReader As System.Data.OleDb.OleDbDataReader
10. objCmd = New System.Data.OleDb.OleDbCommand(strSQL, objConn)
11. dtReader = objCmd.ExecuteReader()
12.
13.
14. dtReader.Close()
15. dtReader = Nothing
16. objConn.Close()
17. objConn = Nothing
|
 |
 |
 |
 |
Date :
2010-05-26 14:54:50 |
By :
msorawich |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียน sql ไปแค่รอบเดียวเองอ่ะคะ ก็ไม่ขึ้นซะแล้ว เนี้ย!คะ เขียนไปแค่นี้เอง
Code (VB.NET)
01. Protected Sub Button1_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button1.Click
02. Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
03. Dim Conn = New MySqlConnection(ConnString)
04. Conn.Open()
05. Dim dtAdapter As New MySqlDataAdapter
06. Dim ds As New Data.DataSet
07.
08. Dim t1 = TextBox1.Text & " 00:00:00 "
09. Dim t2 = TextBox2.Text & " 00:00:00 "
10. Dim SQL = "select ecode,em_name,em_name2,indate,shift,time0,time1,time2, time3, time4, time5, time6, time7, tin, tbout, tbin, tout from shifttime,emper where(substring(em_code, 1, 7) = ecode) and indate between 't1' and 't2' and ebranch = '" & TextBox3.Text & "' order by indate,ecode "
11. Dim Cmd = New MySqlCommand(SQL, Conn)
12. Dim dtreader = Cmd.ExecuteReader()
13. dtAdapter.SelectCommand = Cmd
14. dtAdapter.Fill(ds)
15. GridView1.DataSource = ds
16. GridView1.DataBind()
17. dtreader.Close()
18. dtreader = Nothing
19. End Sub
20. End Class
|
 |
 |
 |
 |
Date :
2010-05-26 15:03:16 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครทราบเลยหรอคะ ช่วยหน่อยนะคะ
|
 |
 |
 |
 |
Date :
2010-05-27 09:18:55 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Quote:There is already an open DataReader associated with this Connection which must be closed first.
ไม่เคยใช้ class mysqlclient ซะด้วย แต่เดาว่าคงเหมือนกับ sqlclient
Code (VB.NET)
01. Protected Sub Button1_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button1.Click
02. Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
03. Dim Conn = New MySqlConnection(ConnString)
04.
05. If Conn.State = ConnectionState.Open Then
06. Conn.Close()
07. End If
08.
09. Conn.Open()
10. Dim dtAdapter As New MySqlDataAdapter
11. Dim ds As New Data.DataSet
12.
13. Dim t1 = TextBox1.Text & " 00:00:00 "
14. Dim t2 = TextBox2.Text & " 00:00:00 "
15. Dim SQL = "select ecode,em_name,em_name2,indate,shift,time0,time1,time2, time3, time4, time5, time6, time7, tin, tbout, tbin, tout from shifttime,emper where(substring(em_code, 1, 7) = ecode) and indate between 't1' and 't2' and ebranch = '" & TextBox3.Text & "' order by indate,ecode "
16. Dim Cmd = New MySqlCommand(SQL, Conn)
17. Dim dtreader = Cmd.ExecuteReader()
18. dtAdapter.SelectCommand = Cmd
19. dtAdapter.Fill(ds)
20. GridView1.DataSource = ds
21. GridView1.DataBind()
22. dtreader.Close()
23. dtreader = Nothing
24. End Sub
25. End Class
|
 |
 |
 |
 |
Date :
2010-05-27 09:41:46 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
error เหมือนเดิมเลยคะ 
|
 |
 |
 |
 |
Date :
2010-05-27 10:21:58 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืมรู้แระ เจอคนหลายใจนี่เอง ต้องเลือกเอาสักอย่างสิ จะ connectionless หรือ connection
อันนี้แบบ connection
01. Protected Sub Button1_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button1.Click
02. Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
03. Dim Conn = New MySqlConnection(ConnString)
04.
05. If Conn.State = ConnectionState.Open Then
06. Conn.Close()
07. End If
08.
09. Conn.Open()
10. Dim ds As New Data.DataSet
11.
12. Dim t1 = TextBox1.Text & " 00:00:00 "
13. Dim t2 = TextBox2.Text & " 00:00:00 "
14. Dim SQL = "select ecode,em_name,em_name2,indate,shift,time0,time1,time2, time3, time4, time5, time6, time7, tin, tbout, tbin, tout from shifttime,emper where(substring(em_code, 1, 7) = ecode) and indate between 't1' and 't2' and ebranch = '" & TextBox3.Text & "' order by indate,ecode "
15. Dim Cmd = New MySqlCommand(SQL, Conn)
16. Dim dtreader = Cmd.ExecuteReader()
17.
18. GridView1.DataSource = dtreader
19. GridView1.DataBind()
20. dtreader.Close()
21. dtreader = Nothing
22. End Sub
23. End Class
แบบ connectionless
01. Protected Sub Button1_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button1.Click
02. Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
03. Dim Conn = New MySqlConnection(ConnString)
04.
05. Dim dtAdapter As New MySqlDataAdapter
06. Dim ds As New Data.DataSet
07.
08. Dim t1 = TextBox1.Text & " 00:00:00 "
09. Dim t2 = TextBox2.Text & " 00:00:00 "
10. Dim SQL = "select ecode,em_name,em_name2,indate,shift,time0,time1,time2, time3, time4, time5, time6, time7, tin, tbout, tbin, tout from shifttime,emper where(substring(em_code, 1, 7) = ecode) and indate between 't1' and 't2' and ebranch = '" & TextBox3.Text & "' order by indate,ecode "
11. Dim Cmd = New MySqlCommand(SQL, Conn)
12. dtAdapter.SelectCommand = Cmd
13. dtAdapter.Fill(ds)
14. GridView1.DataSource = ds
15. GridView1.DataBind()
16. End Sub
17. End Class
|
 |
 |
 |
 |
Date :
2010-05-27 10:27:48 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาแบบ2อ่ะคะ แต่ทำไมข้อมูลมันไม่มาอ่ะคะ มันมีอะไรหายไปป่าว แล้วไม่ต้องเปิด conn หรอคะ
|
 |
 |
 |
 |
Date :
2010-05-27 10:38:11 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็บอกว่า connection less แล้วจะเปิด connection เพื่ออะไรล่ะครับ
ส่วนไม่มี data ลองตรวจเงื่อนไข where ดูดีๆ ครับ
|
 |
 |
 |
 |
Date :
2010-05-27 10:54:15 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันแสดงข้อมูลแล้วแหละคะ พอดีว่าใน mysql มันไม่ต้องใส่เวลา ใส่แค่วันที่พอ
แต่ทำไมพอดึงข้อมูลมาหน้าเว็บมันไม่แสดงภาษาไทย ก็ไม่รู้อ่ะคะ พี่พอจะทราบวิธีไหมคะ 
|
 |
 |
 |
 |
Date :
2010-05-27 11:20:49 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|