see the follow code:
can return more than one recordset/table
the datagrid can show more than one table at a time.
1.the problem is how to store more than one table in a dataset at a time.
2.see sql(2),sql(3), the new table 't1' is empty, after exec sql(3) will meet a "System.Data.OleDb.OleDbException",the sql(2) can pass without return recordset, but sql(3) return a null recordset(maybe). What should I do.
thanks.
Public Function m_execsql()
Dim connStr As String
connStr = "User ID=sa;Password=sa;Initial Catalog=Northwind;Provider=""SQLOLEDB.1"";Data Source=MINGLEI"
conn = New System.Data.OleDb.OleDbConnection(connStr)
conn.Open()
Dim sql(3) As String
sql(0) = "select * from products;"
sql(1) = "select * from orders;"
sql(2) = "create table t1;"
sql(3) = "seletc * from t1;"
Dim i As Integer
For i = 0 To sql.GetUpperBound(0) - 1
Try
da = New OleDb.OleDbDataAdapter(sql(i), conn)
Catch e As Exception
MessageBox.Show(e.Message)
End Try
'Try
ds = New DataSet("dsTable")
dt = New DataTable
da.Fill(ds)
'grd.SetDataBinding(ds, i.ToString)
grd.DataSource = dt
'Catch eds As Exception
' MessageBox.Show(eds.Message)
'End T
Next
conn.Close()
conn = Nothing
End Functioniqueen, you can use multiple data adapters to fill one dataset or if your sql statement returned more than one result set.
Here's more from MS KB:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpopulatingdatasetfromdataadapter.asp
You may want post in .Net section too...
Showing posts with label recordset. Show all posts
Showing posts with label recordset. Show all posts
Wednesday, March 7, 2012
Subscribe to:
Posts (Atom)