I am using the code below to populate a SqlDataAdapter, fill a DataTable, and then bid to a Gridview. For some strange reason my Gridview is not displaying. Thanks for any help.
Dim dt
AsDataTable =
NewDataTable()
Dim conStr
AsString =
"Data Source=JSE;Initial Catalog=Test_UAT;Integrated Security=True"
Dim con
AsSqlConnection =
NewSqlConnection(conStr)
Dim com
AsSqlCommand =
NewSqlCommand("jse_BusinessInformation.getSentEmail", con)
I recommend basic troubleshooting. I assume the result set is empty. Set a breakpoint and verify the DataTable has rows.
The following code has possible errors. First, there's no validation and we can't determine of the input contain values. Second, there are two dates that are treated like string which is odd.
Oddly enough the dataset has the right amount of columns, but no rows. On my future posts I will be more comprehensive in sharing more about the other components related to the codes i.e. the stored proc and table structure.
Oddly enough the dataset has the right amount of columns, but no rows. On my future posts I will be more comprehensive in sharing more about the other components related to the codes i.e. the stored proc and table structure.
That's not odd at all. Your result set is empty. There is nothing to data bind. I recommend using the GridView's empty data template to display a message to the user when this situation happens.
Member
282 Points
298 Posts
GridView not displaying
Oct 01, 2019 04:39 PM|rkrex|LINK
Hi Friends,
I am using the code below to populate a SqlDataAdapter, fill a DataTable, and then bid to a Gridview. For some strange reason my Gridview is not displaying. Thanks for any help.
Dim dt As DataTable = New DataTable()
Dim conStr As String = "Data Source=JSE;Initial Catalog=Test_UAT;Integrated Security=True"
Dim con As SqlConnection = New SqlConnection(conStr)
Dim com As SqlCommand = New SqlCommand("jse_BusinessInformation.getSentEmail", con)
com.Parameters.AddWithValue("@StartDate", SqlDbType.NVarChar).Value = StartDateTxt.Text
com.Parameters.AddWithValue("@EndDate", SqlDbType.NVarChar).Value = EndDateTxt.Text
com.Parameters.AddWithValue("@BatchFlag", SqlDbType.NVarChar).Value = EmailFlagDdl.Text
com.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(com)
'Try
con.Open()
da.Fill(dt)
If con.State = ConnectionState.Open Then con.Close()
GridView1.DataSource = dt
GridView1.DataBind()
All-Star
53001 Points
23587 Posts
Re: GridView not displaying
Oct 01, 2019 06:57 PM|mgebhard|LINK
I recommend basic troubleshooting. I assume the result set is empty. Set a breakpoint and verify the DataTable has rows.
The following code has possible errors. First, there's no validation and we can't determine of the input contain values. Second, there are two dates that are treated like string which is odd.
Again, taking the time to debug should help you determine where the bugs are in your logic.
Member
282 Points
298 Posts
Re: GridView not displaying
Oct 02, 2019 02:12 PM|rkrex|LINK
Oddly enough the dataset has the right amount of columns, but no rows. On my future posts I will be more comprehensive in sharing more about the other components related to the codes i.e. the stored proc and table structure.
All-Star
53001 Points
23587 Posts
Re: GridView not displaying
Oct 02, 2019 02:30 PM|mgebhard|LINK
That's not odd at all. Your result set is empty. There is nothing to data bind. I recommend using the GridView's empty data template to display a message to the user when this situation happens.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview.emptydatatemplate?view=netframework-4.8