473,498 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid, SQL Adapter question


A friend of mine is doing some datagrids on a web page, and was using the
SQL data adapter on the design view of the page.

He is sorting the datagrid on each of the columns as a user clicks on the
column header. He showed me how he was creating the page, and we had a
question about the wizard that sets up the connection.

In it, he had to specify the sql server, and it gave him an option to use an
existing stored procedure. He picked a stored procedure out of the list he
was provided.

The stored procedure was a select query, and returned 3 fields. The
question though - is there a way to pass a parameter - like a userid - into
the stored procedure in setting up that wizard. Or, is there a way to call
it with a parameter and override what the code in the #region section of the
codebehind has in it?

The code follows....

Thanks,
SC

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand

'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "sp_WIP_Centerfire", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("model", "model"), New
System.Data.Common.DataColumnMapping("ramac", "ramac"), New
System.Data.Common.DataColumnMapping("cal", "cal"), New
System.Data.Common.DataColumnMapping("serial", "serial"), New
System.Data.Common.DataColumnMapping("condition", "condition"), New
System.Data.Common.DataColumnMapping("price", "price"), New
System.Data.Common.DataColumnMapping("id", "id")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "[sp_WIP_Centerfire]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE" ,
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(0, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=mysqlserver;
database=WIP; User ID=login-pwd; Password=login-pwd; Persist" & _
" Security Info=True;packet size=4096"
'
End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
SqlDataAdapter1.Fill(ds, "tblWIP")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "tblWIP"
DataGrid1.DataBind()
Session("ds") = ds

End Sub

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim ds As DataSet = CType(Session("ds"), DataSet)
Dim dv As New DataView(ds.Tables("tblWIP"))

'Only have to specify Desc b/c default is to ASC
'ViewState is Case Sensitive
Dim desc As Boolean
If viewstate("desc") Is Nothing Then
desc = False
Else
desc = CBool(viewstate("desc"))
End If

dv.Sort = e.SortExpression

If desc = True Then
dv.Sort &= " DESC"
End If

viewState("desc") = Not desc

DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub

Nov 18 '05 #1
1 3529
Add a parameter to SqlSelectCommand1 in Page_Load. The automatically
generated code already includes a statement for adding a parameter. Use it
as an example.

Eliyahu

"Goober at christianDOTnet" <me@privacy.net> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl...

A friend of mine is doing some datagrids on a web page, and was using the
SQL data adapter on the design view of the page.

He is sorting the datagrid on each of the columns as a user clicks on the
column header. He showed me how he was creating the page, and we had a
question about the wizard that sets up the connection.

In it, he had to specify the sql server, and it gave him an option to use an existing stored procedure. He picked a stored procedure out of the list he was provided.

The stored procedure was a select query, and returned 3 fields. The
question though - is there a way to pass a parameter - like a userid - into the stored procedure in setting up that wizard. Or, is there a way to call it with a parameter and override what the code in the #region section of the codebehind has in it?

The code follows....

Thanks,
SC

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand

'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "sp_WIP_Centerfire", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("model", "model"), New
System.Data.Common.DataColumnMapping("ramac", "ramac"), New
System.Data.Common.DataColumnMapping("cal", "cal"), New
System.Data.Common.DataColumnMapping("serial", "serial"), New
System.Data.Common.DataColumnMapping("condition", "condition"), New
System.Data.Common.DataColumnMapping("price", "price"), New
System.Data.Common.DataColumnMapping("id", "id")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "[sp_WIP_Centerfire]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE" ,
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(0, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=mysqlserver;
database=WIP; User ID=login-pwd; Password=login-pwd; Persist" & _
" Security Info=True;packet size=4096"
'
End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
SqlDataAdapter1.Fill(ds, "tblWIP")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "tblWIP"
DataGrid1.DataBind()
Session("ds") = ds

End Sub

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim ds As DataSet = CType(Session("ds"), DataSet)
Dim dv As New DataView(ds.Tables("tblWIP"))

'Only have to specify Desc b/c default is to ASC
'ViewState is Case Sensitive
Dim desc As Boolean
If viewstate("desc") Is Nothing Then
desc = False
Else
desc = CBool(viewstate("desc"))
End If

dv.Sort = e.SortExpression

If desc = True Then
dv.Sort &= " DESC"
End If

viewState("desc") = Not desc

DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub

Nov 18 '05 #2

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

Similar topics

3
2727
by: Steve Donnor | last post by:
Here's my question.. I can't seem to get my datagrid to refresh. I have a Dataset that automagically populates the datagrid. It's a two parameter SQL statement that I am using. Here's an...
3
2193
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
5
2563
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
3769
by: aylin_sk | last post by:
I'm trying to list my data into my datagrid creating stored procedures in oracle db..My data includes questions for a survey....It's simple but i cant see my datagrid in my web form..I'm now going...
4
2339
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
4
4302
by: slaprade | last post by:
I am loading a weeks worth of web logs into a dataset using Imports Microsoft.Data.Odbc These are text - fixed length fields so I have written a schema for them. The adapter fill looks like this...
7
7728
by: Wayne Wengert | last post by:
I am using VB with a Windows NET application. I have a datagrid in which the user can add rows using the "*" row. I want to detect whenever the user has added a row. I found the following code at...
4
1274
by: Peter Newman | last post by:
Im just toying with vb.net and am trying to find out howw things work. i have managed to come up with the following code that will access a table in a sql2005 server . what id like to do is...
1
1580
by: WayneM | last post by:
I have compact framework app that I was trying to test out on a windows form, but I cannot get past the very first step of simply filling a DataGrid from a DataSet. My code is Dim sqlStmt As...
0
7004
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...
0
7167
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,...
0
7208
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...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
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...

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.