473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Datagrid fails to fill

I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #1
6 1600
where is the DataSource set??
try this
dg1.DataSource = Ds11

"JeffB" wrote:
I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #2
To fill datagrid, there are following steps:

1. Create a new DataAdapter:
Although there are several different ways, simplest
way is:
Dim dap As New SqlDataAdapter(QueryString,
ConnectionString)

2. Fill data to a DataSet or DataTable:
Dim ds As New DataSet();
dap.Fill(ds)

3. Fill Datagrid with data
dg1.DataSource = ds
dg1.DataBind()

So check your steps to see if you missed any step.

Elton Wang
-----Original Message-----
I have tried several different methods of getting a datagrid to fill withinformation. Below is the code I'm now using. When viewed in the browser andthe text box filled with a parameter value (i.e. CA for Calif), the datagridsheader is displayed when the button is clicked, but no data is displayed.I used SQL Profiler and can see that the query comes across with theparameter, and if I take that query string and use it exactly in QueryAnalyzer it executes and displays the data I expect. I just can't seem to getthe datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private SubInitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t() '
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packetsize=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx" '
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", NewSystem.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), NewSystem.Data.Common.DataColumnMapping ("au_lname", "au_lname"), NewSystem.Data.Common.DataColumnMapping ("au_fname", "au_fname"), NewSystem.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2)) '
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US") CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )
End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidato r
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web FormDesigner.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA' 'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

.

Nov 19 '05 #3
Vinay:

I tried both your suggestion and "dg1.DataSource = Ds11.Tables("authors")

and still get the same thing. The datagrid headers and no data.

Jeff

"vinay" wrote:
where is the DataSource set??
try this
dg1.DataSource = Ds11

"JeffB" wrote:
I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #4
Vinay:

Thanks, got it now.

"vinay" wrote:
where is the DataSource set??
try this
dg1.DataSource = Ds11

"JeffB" wrote:
I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #5
Vinay:

I now see why I didn't add the line you have listed below. This information
is entered into the properties of the datagrid on the WebForm1.aspx page.
There is a place for DataSource, DataMember, and DataKeyField. I had this
same information there. Why wasn't it being used.

I went back and tested, and took these parameters out of the properties and
my datagrid in the IDE goes back to a default datagrid with column names 0,
1, and 2, but when I view the page in the browser, it works and displays
properly.

Do you know why, or can some tell me why?

Thanks again.

"vinay" wrote:
where is the DataSource set??
try this
dg1.DataSource = Ds11

"JeffB" wrote:
I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #6
Pls check the order
sqlDA1.Fill(Ds11, "Customers")
dg1.DataSource = Ds11
dg1.DataBind()
"JeffB" wrote:
Vinay:

I now see why I didn't add the line you have listed below. This information
is entered into the properties of the datagrid on the WebForm1.aspx page.
There is a place for DataSource, DataMember, and DataKeyField. I had this
same information there. Why wasn't it being used.

I went back and tested, and took these parameters out of the properties and
my datagrid in the IDE goes back to a default datagrid with column names 0,
1, and 2, but when I view the page in the browser, it works and displays
properly.

Do you know why, or can some tell me why?

Thanks again.

"vinay" wrote:
where is the DataSource set??
try this
dg1.DataSource = Ds11

"JeffB" wrote:
I have tried several different methods of getting a datagrid to fill with
information. Below is the code I'm now using. When viewed in the browser and
the text box filled with a parameter value (i.e. CA for Calif), the datagrids
header is displayed when the button is clicked, but no data is displayed.
I used SQL Profiler and can see that the query comes across with the
parameter, and if I take that query string and use it exactly in Query
Analyzer it executes and displays the data I expect. I just can't seem to get
the datagrid to display data.

What am I missing?

Public Class WebForm1
Inherits System.Web.UI.Page

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.sqlConn = New System.Data.SqlClient.SqlConnection
Me.sqlDA1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).BeginIni t()
'
'sqlConn
'
Me.sqlConn.ConnectionString = "workstation id=DOTSW27182;packet
size=4096;user id=xxx;source=dotswapps;pe" & _
"rsist security info=True;initial catalog=pubs;password=xxx"
'
'sqlDA1
'
Me.sqlDA1.SelectCommand = Me.SqlSelectCommand1
Me.sqlDA1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "authors", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("au_id", "au_id"), New
System.Data.Common.DataColumnMapping("au_lname", "au_lname"), New
System.Data.Common.DataColumnMapping("au_fname", "au_fname"), New
System.Data.Common.DataColumnMapping("city", "city"), New
System.Data.Common.DataColumnMapping("state", "state")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCommand1.Connection = Me.sqlConn
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@st", System.Data.SqlDbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSetName = "ds1"
Me.Ds11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Ds11, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub
Protected WithEvents tbState As System.Web.UI.WebControls.TextBox
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents sqlDA1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Me.sqlConn.Open()
sqlDA1.SelectCommand.Parameters("@st").Value = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds11, "Customers")
Me.sqlConn.Close()
' End If
' )
Catch
'ex As Exception
'Console.WriteLine = ex.Message.ToString

End Try
'Me.SqlSelectCommand1.Parameters("@St").Value = 'CA'
'Me.SqlSelectCommand1.ExecuteReader()
'Me.sqlDA1.Fill(Ds11)
'Me.sqlConn.Close()

End Sub
End Class

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: - R | last post by:
Hello all. I'm new to .Net so please help me out. I have a application with several "Threads" running to observe various things. From time to time each thread need to add an log entry, which...
3
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender,...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Hai Nguyen | last post by:
I'm building a form so that customer can fill in their data (with a lot of texboxes). I decided to use datagrid. I don't know if I'm on the right track. I was able to build a array of datagrids...
4
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
0
by: Nigpig | last post by:
Hi I have a datagrid with button columns that about 1 in 4 times fails to completely fill the columns. When this happens the rest of the page is not completed but terminates rendering after the...
0
by: nigel | last post by:
Hi I have a datagrid with button columns that about 1 in 4 times fails to completely fill the columns. When this happens the rest of the page is not completed but terminates rendering after the...
6
by: rcoco | last post by:
Hi, I have a datagrid that is ment to insert data. But when I run the form only the header appears. I would like some advise from you all and solve this problem I'm using visual studio 2003. My...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.