georgepatotk Posted May 10, 2004 Posted May 10, 2004 Sub BindData() Dim SalesOrderConn As New SqlClient.SqlConnection(Session.Item("ConnectionString")) Dim SalesOrderdat As New SqlClient.SqlDataAdapter Dim SalesOrderdts As New DataSet SalesOrderdat.SelectCommand.CommandText = "SELECT * FROM tblSalesOrder WHERE Approved = 0 AND Cancelled = 0" SalesOrderdat.SelectCommand.Connection = SalesOrderConn SalesOrderdat.SelectCommand.ExecuteReader() SalesOrderdat.Fill(SalesOrderdts) dgSalesOrder.DataSource = SalesOrderdat SalesOrderConn.Close() End Sub Regarding to the above codes: most of the time I used drag and drop method. I am trying to use it in programmatic way but it don't work. Why?? Quote George C.K. Low
Administrators PlausiblyDamp Posted May 10, 2004 Administrators Posted May 10, 2004 If you are using the .ExecuteReader method then you need to open the connection first, however in this case you can remove the line SalesOrderdat.SelectCommand.ExecuteReader() and it should work Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted May 18, 2004 Author Posted May 18, 2004 the solution is Sub BindData() Dim SalesOrderConn As New SqlClient.SqlConnection(Session.Item("ConnectionString")) Dim SalesOrderdat As New SqlClient.SqlDataAdapter Dim SalesOrderdts As New DataSet If SalesOrderConn.State = ConnectionState.Closed Then SalesOrderConn.Open() End If SalesOrderdat.SelectCommand = New SqlClient.SqlDataAdapter SalesOrderdat.SelectCommand.CommandText = "SELECT * FROM tblSalesOrder WHERE Approved = 0 AND Cancelled = 0" SalesOrderdat.SelectCommand.Connection = SalesOrderConn SalesOrderdat.Fill(SalesOrderdts) dgSalesOrder.DataSource = SalesOrderdat SalesOrderConn.Close() End Sub Quote George C.K. Low
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.