473,625 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

End Sub
End Class

Nov 19 '05 #1
6 1610
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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

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,
ConnectionStrin g)

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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private SubInitializeComp onent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit() '
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acketsize=4096;us er id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx" '
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Co mmon.DataTableM apping() {New
System.Data.Co mmon.DataTableM apping("Table", "authors", NewSystem.Data.Co mmon.DataColumn Mapping() {New
System.Data.Co mmon.DataColumn Mapping("au_id" , "au_id"), NewSystem.Data.Co mmon.DataColumn Mapping ("au_lname", "au_lname") , NewSystem.Data.Co mmon.DataColumn Mapping ("au_fname", "au_fname") , NewSystem.Data.Co mmon.DataColumn Mapping("city", "city"), New
System.Data.Co mmon.DataColumn Mapping("state" , "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sq lClient.SqlPara meter("@st", System.Data.Sql DbType.VarChar, 2)) '
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US") CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()
End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI. WebControls.Req uiredFieldValid ator
Protected WithEvents ValidationSumma ry1 As
System.Web.UI. WebControls.Val idationSummary
'NOTE: The following placeholder declaration is required by the Web FormDesigner.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

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

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventAr gs) 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.EventAr gs) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA' 'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

End Sub
End Class

.

Nov 19 '05 #3
Vinay:

I tried both your suggestion and "dg1.DataSo urce = Ds11.Tables("au thors")

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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

End Sub
End Class

Nov 19 '05 #6
Pls check the order
sqlDA1.Fill(Ds1 1, "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.P age

Dim state As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.sqlConn = New System.Data.Sql Client.SqlConne ction
Me.sqlDA1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.Ds11 = New TestPubs.ds1
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).Beg inInit()
'
'sqlConn
'
Me.sqlConn.Conn ectionString = "workstatio n id=DOTSW27182;p acket
size=4096;user id=xxx;source=d otswapps;pe" & _
"rsist security info=True;initi al catalog=pubs;pa ssword=xxx"
'
'sqlDA1
'
Me.sqlDA1.Selec tCommand = Me.SqlSelectCom mand1
Me.sqlDA1.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "authors", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("au_id", "au_id"), New
System.Data.Com mon.DataColumnM apping("au_lnam e", "au_lname") , New
System.Data.Com mon.DataColumnM apping("au_fnam e", "au_fname") , New
System.Data.Com mon.DataColumnM apping("city", "city"), New
System.Data.Com mon.DataColumnM apping("state", "state")})} )
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT au_id, au_lname,
au_fname, city, state FROM authors WHERE (state = @st)"
Me.SqlSelectCom mand1.Connectio n = Me.sqlConn
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@st", System.Data.Sql DbType.VarChar, 2))
'
'Ds11
'
Me.Ds11.DataSet Name = "ds1"
Me.Ds11.Locale = New System.Globaliz ation.CultureIn fo("en-US")
CType(Me.Ds11, System.Componen tModel.ISupport Initialize).End Init()

End Sub
Protected WithEvents tbState As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnSubmit As System.Web.UI.W ebControls.Butt on
Protected WithEvents sqlConn As System.Data.Sql Client.SqlConne ction
Protected WithEvents sqlDA1 As System.Data.Sql Client.SqlDataA dapter
Protected WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Protected WithEvents Ds11 As TestPubs.ds1
Protected WithEvents dg1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnSubmit.Click
Try
Me.sqlConn.Open ()
sqlDA1.SelectCo mmand.Parameter s("@st").Valu e = tbState.Text
DataBind()
dg1.DataBind()
sqlDA1.Fill(Ds1 1, "Customers" )
Me.sqlConn.Clos e()
' End If
' )
Catch
'ex As Exception
'Console.WriteL ine = ex.Message.ToSt ring

End Try
'Me.SqlSelectCo mmand1.Paramete rs("@St").Valu e = 'CA'
'Me.SqlSelectCo mmand1.ExecuteR eader()
'Me.sqlDA1.Fill (Ds11)
'Me.sqlConn.Clo se()

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
1548
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 is displayed on a form (a datagrid on a form) there is no database, but i created a dataset using the designer. One Entity/Table is called Log and contains the log-entries.
3
2995
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, System.EventArgs e) {try{ DataSet ds = dgMembers.DataSource as DataSet;
3
4869
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 the best method? Do you have a sample of how to do this?
0
959
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 programmactically. Here is my situation. From : mm/dd/yy To: mm/dd/yy Fill (button)
4
4528
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 "courseload". here's the fields of every table in my dataset. "Course" table CourseID
3
2279
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 than the key value that are stored in the table. It works well if the comboboxes are selected when the row is created.
0
984
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 incomplete grid. The grid is placed within a usercontrol form. I think this could be the same problem as another web user control form in that it stops sometimes when populating textbox controls. It always
0
989
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 incomplete grid. The grid is placed within a usercontrol form. I think this could be the same problem as another web user control form
6
3701
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 code looks like this: private void Fill() { DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.