 |
|
|
 |
 |
|
ลองเช็ค ค่าใน 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)
Dim objConn As System.Data.OleDb.OleDbConnection
Dim objCmd As System.Data.OleDb.OleDbCommand
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
objConn = New System.Data.OleDb.OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
Dim dtReader As System.Data.OleDb.OleDbDataReader
objCmd = New System.Data.OleDb.OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** DataReader ***'
dtReader.Close()
dtReader = Nothing
objConn.Close()
objConn = Nothing
|
 |
 |
 |
 |
Date :
2010-05-26 14:54:50 |
By :
msorawich |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียน sql ไปแค่รอบเดียวเองอ่ะคะ ก็ไม่ขึ้นซะแล้ว เนี้ย!คะ เขียนไปแค่นี้เอง
Code (VB.NET)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
Dim Conn = New MySqlConnection(ConnString)
Conn.Open()
Dim dtAdapter As New MySqlDataAdapter
Dim ds As New Data.DataSet
Dim t1 = TextBox1.Text & " 00:00:00 "
Dim t2 = TextBox2.Text & " 00:00:00 "
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 "
Dim Cmd = New MySqlCommand(SQL, Conn)
Dim dtreader = Cmd.ExecuteReader()
dtAdapter.SelectCommand = Cmd 'Adapter เป็นตัวเชื่อมระหว่างฐานข้อมูลกับตัวระบบ
dtAdapter.Fill(ds) 'เป็นการรันsql
GridView1.DataSource = ds
GridView1.DataBind()
dtreader.Close()
dtreader = Nothing
End Sub
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)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
Dim Conn = New MySqlConnection(ConnString)
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
Conn.Open()
Dim dtAdapter As New MySqlDataAdapter
Dim ds As New Data.DataSet
Dim t1 = TextBox1.Text & " 00:00:00 "
Dim t2 = TextBox2.Text & " 00:00:00 "
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 "
Dim Cmd = New MySqlCommand(SQL, Conn)
Dim dtreader = Cmd.ExecuteReader()
dtAdapter.SelectCommand = Cmd 'Adapter เป็นตัวเชื่อมระหว่างฐานข้อมูลกับตัวระบบ
dtAdapter.Fill(ds) 'เป็นการรันsql
GridView1.DataSource = ds
GridView1.DataBind()
dtreader.Close()
dtreader = Nothing
End Sub
End Class
|
 |
 |
 |
 |
Date :
2010-05-27 09:41:46 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
error เหมือนเดิมเลยคะ 
|
 |
 |
 |
 |
Date :
2010-05-27 10:21:58 |
By :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืมรู้แระ เจอคนหลายใจนี่เอง ต้องเลือกเอาสักอย่างสิ จะ connectionless หรือ connection
อันนี้แบบ connection
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
Dim Conn = New MySqlConnection(ConnString)
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
Conn.Open()
Dim ds As New Data.DataSet
Dim t1 = TextBox1.Text & " 00:00:00 "
Dim t2 = TextBox2.Text & " 00:00:00 "
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 "
Dim Cmd = New MySqlCommand(SQL, Conn)
Dim dtreader = Cmd.ExecuteReader()
GridView1.DataSource = dtreader
GridView1.DataBind()
dtreader.Close()
dtreader = Nothing
End Sub
End Class
แบบ connectionless
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString = "Server=192.168.10.88;database=pt;UID=root;"
Dim Conn = New MySqlConnection(ConnString)
Dim dtAdapter As New MySqlDataAdapter
Dim ds As New Data.DataSet
Dim t1 = TextBox1.Text & " 00:00:00 "
Dim t2 = TextBox2.Text & " 00:00:00 "
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 "
Dim Cmd = New MySqlCommand(SQL, Conn)
dtAdapter.SelectCommand = Cmd 'Adapter เป็นตัวเชื่อมระหว่างฐานข้อมูลกับตัวระบบ
dtAdapter.Fill(ds) 'เป็นการรันsql
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
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 :
^^ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|