lestat0109
07-24-2012, 01:21 PM
I have created a datatable/tableadapters using the designer and would like to know how I fill/refer to this datatable in code.
ASP.NET 4 / VB
Please help.
ASP.NET 4 / VB
Please help.
|
||||
Calling a datatablelestat0109 07-24-2012, 01:21 PM I have created a datatable/tableadapters using the designer and would like to know how I fill/refer to this datatable in code. ASP.NET 4 / VB Please help. lestat0109 07-25-2012, 01:18 PM 96 views and no response? Im a little worried that my being new to ASP.net means I worded my question improperly. alykins 07-25-2012, 02:16 PM It's more of a "don't know what you are asking" .... no code offered and do not know what it is you're trying to do... loading a datatable with data is done by... Dim connstring as String = "... connectionstring.com ... " Dim _Query as String = "SELECT * FROM tbl_Demo Dim dt as new DataTable() Dim conn as new SqlConnection(connstring) Dim da as new SqlDataAdapter(_Query,conn) conn.Open() da.Fill(dt) conn.Close() Refs: datatables (http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx) dataadapters (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx#Y0) lestat0109 07-25-2012, 02:42 PM It's more of a "don't know what you are asking" .... no code offered and do not know what it is you're trying to do... loading a datatable with data is done by... Dim connstring as String = "... connectionstring.com ... " Dim _Query as String = "SELECT * FROM tbl_Demo Dim dt as new DataTable() Dim conn as new SqlConnection(connstring) Dim da as new SqlDataAdapter(_Query,conn) conn.Open() da.Fill(dt) conn.Close() Refs: datatables (http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx) dataadapters (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx#Y0) Ah, gotcha. Ill elaborate. I have already set the connection string in the dataset designer. I have already created a query in the tableadapter for the information i would like to fill the datatable with. I have a function that requires that I pass a datatable to it and i have no idea how to point that function to the datatable i have created in the designer, rather than recreate the whole thing in code only. (like your example above) The datatable is called dtTest and the tableadapter is called taTest. alykins 07-25-2012, 03:21 PM private Sub something() ..... Dim dt as new DataTable() FillMyTable(dt) CallSomething(dt) ...... End Sub private Sub FillMyTable(ByVal dt as DataTable) Dim connstring as String = "... connectionstring.com ... " Dim _Query as String = "SELECT * FROM tbl_Demo Dim conn as new SqlConnection(connstring) Dim da as new SqlDataAdapter(_Query,conn) conn.Open() da.Fill(dt) conn.Close() return dt End Sub private Sub CallSomething(ByVal dt as DataTable) foreach r as DataRow in dt.Rows 'do something Next End Sub lestat0109 07-25-2012, 03:34 PM private Sub something() ..... Dim dt as new DataTable() FillMyTable(dt) CallSomething(dt) ...... End Sub private Sub FillMyTable(ByVal dt as DataTable) Dim connstring as String = "... connectionstring.com ... " Dim _Query as String = "SELECT * FROM tbl_Demo Dim conn as new SqlConnection(connstring) Dim da as new SqlDataAdapter(_Query,conn) conn.Open() da.Fill(dt) conn.Close() return dt End Sub private Sub CallSomething(ByVal dt as DataTable) foreach r as DataRow in dt.Rows 'do something Next End Sub Is there any reason why i cant use the one datatable i have already created? http://i1210.photobucket.com/albums/cc409/lestat0109/DataTable.png how would i reference this dtTest that i have created through code. I want to use it rather than create a new one through code. alykins 07-25-2012, 04:10 PM you can use whatever you want... i just was copy/pasting and didn't want to change all references... honestly i have no clue how to do it via "wizard"... I hate wizards... doing it via code is always preferred... I tend to not even use the screen UI for setting properties- I usually set them via code. I have no clue what your code looks like or where that object is created... when you are on the webpage, hit F7 to go to code... you should see your object created in there somewhere. it might be in the designer (don't change things in there unless you know what you're doing- it will break)... the designer is a partial class though... Example Page.aspx <- asp.net web page with html elements Page.aspx.vb <- vb code behind file page.aspx.designer.vb <- partial class used to create objects and delegates lestat0109 07-25-2012, 04:57 PM ok, well, thanks. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum