populating an ado.net datatable

Results 1 to 2 of 2

Thread: populating an ado.net datatable

  1. #1
    Join Date
    Dec 1969

    Default populating an ado.net datatable

    i have a script that is failing to properly populate a datatable. you can see from the section of the code that i am including below that i do a response.write of the count property of the rows collection right after the table is supposed to be filled with data in the script. well, the output on my screen is 0 from that response.write, which means that the datatable is empty when it is supposed to be full. the underlying table in sql server has 2 records in it, so the count should be 2 instead of 0.<BR><BR>this is probably a simple problem with a simple solution. can anyone show me how to fix the code below so that the datatable object is filled properly? i will then need to iterate through the table and send its data into other non-display objects to automate a process, so it is not as simple as just filling a listbox or something. but the section of code below should only take a minor amount of tweeking. can you show me how?<BR><BR>thanks in advance. here is the code:<BR>-----------------------------------------------------------------<BR> Sub Button_Click(sender As Object, e As EventArgs)<BR> Dim sqlString As String = "SELECT UserEmail FROM PracticeCommUsers "<BR>&#039; Label1.Text = "Organizations"<BR> BindData(sqlString)<BR><BR> Dim from As String = FromAddressTextBox.Text<BR> Dim mailto As String <BR> Dim subject As String = SubjectTextBox.Text<BR> Dim body As String = BodyTextBox.Text<BR><BR> Dim myConnection As SqlConnection<BR> Dim objDataset As DataSet<BR> Dim objSQLDataAdapter As SQLDataAdapter<BR> Dim myCommand As SqlCommand<BR> Dim tblEmailAddresses As DataTable<BR><BR> myConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))<BR> myConnection.Open()<BR><BR> objSQLDataAdapter = New SqlDataAdapter()<BR> objDataset = New DataSet()<BR> tblEmailAddresses = New DataTable()<BR><BR> Dim strSQL as String = sqlString<BR><BR> myCommand = New SqlCommand(strSQL, myConnection)<BR> myCommand.CommandType = CommandType.Text<BR><BR> objSQLDataAdapter.SelectCommand = myCommand<BR> objSQLDataAdapter.Fill(objDataset, "tblEmailAddresses")<BR>Response.Write(tblEmailAdd resses.Rows.Count)<BR>&#039; many lines of subsequent processing code that aren&#039;t relevant here<BR>END SUB<BR>-----------------------------------------------------------------

  2. #2
    Join Date
    Dec 1969

    Default RE: populating an ado.net datatable

    The Table u created is new Table (tblEmailAddresses)<BR>But u r not refering to the tblEmailAddresses Table of Dataset <BR>Get tblEmailAddresses from Dataset<BR>tblEmailAddresses = objDataset.Tables["tblEmailAddresses"]<BR>then u check the tblEmailAddresses.Rows.Count.<BR>Response.Write(tb lEmailAddresses.Rows.Count) <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts