!! Help Binding A StoredProcedure record result to the Data Set and bind it to DataGrid

!! Help Binding A StoredProcedure record result to the Data Set and bind it to DataGrid

Post by budh » Fri, 28 Sep 2001 17:10:02



Hi All,

Can anyone help me, i was trying to set my record result which got from
executing one storedProcedure by the SQLDataAdapter, and
then the result will set to the Data Set Object which also will be bind
together with DataGrid.

Is it possible ? My problem is i can't set the fill argument as a
storedprocedure which has the parameter

Dim nwindConn As SqlConnection = New SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")


nwindConn)
selectCMD.CommandTimeout = 30


SqlDbType.NChar, 5))

Request("txCustomerID")

Dim custDA As SqlDataAdapter = New SqlDataAdapter

custDA.SelectCommand = selectCMD

nwindConn.Open()

Dim custDS As DataSet = New DataSet
custDA.Fill(custDS, "Customers")
nwindConn.Close()

MyDataGrid.DataSource=DS.Tables("Customers").DefaultView
MyDataGrid.DataBind()

My stored procedure is :


As

Can anyone advise me ? for now i still getting the error which tell me the
'StoredProcedurName' wasn't recognized.

Regards,

Budhy SB

 
 
 

!! Help Binding A StoredProcedure record result to the Data Set and bind it to DataGrid

Post by Bill Andreozz » Sat, 29 Sep 2001 01:29:56


Here's one way of doing it. (passing in a reference to: a stored proc (just the proc name), command object (with parameters), and a ref to a datagrid.

private bool FillDataGrid( string strStoredProc, ref SqlCommand dbCmd, ref DataGrid dg )

{

SqlDataAdapter dbAdap = new SqlDataAdapter();

DataSet ds = new DataSet();

// Verify that we are still connected

if ( m_dbConn.State != ConnectionState.Open ) OpenDbConnection();

// Populate command object

dbCmd.Connection = m_dbConn;

dbCmd.CommandText = strStoredProc;

dbCmd.CommandType = CommandType.StoredProcedure;

dbAdap.SelectCommand = dbCmd;

dbAdap.Fill( ds, "Result" );

dg.DataSource = ds;

dg.DataBind();

return true;

Quote:}// End of FillDataGrid

thanks - bill

> Hi All,

> Can anyone help me, i was trying to set my record result which got from
> executing one storedProcedure by the SQLDataAdapter, and
> then the result will set to the Data Set Object which also will be bind
> together with DataGrid.

> Is it possible ? My problem is i can't set the fill argument as a
> storedprocedure which has the parameter

> Dim nwindConn As SqlConnection = New SqlConnection("Data
> Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")


> nwindConn)
> selectCMD.CommandTimeout = 30


> SqlDbType.NChar, 5))

> Request("txCustomerID")

> Dim custDA As SqlDataAdapter = New SqlDataAdapter

> custDA.SelectCommand = selectCMD

> nwindConn.Open()

> Dim custDS As DataSet = New DataSet
> custDA.Fill(custDS, "Customers")
> nwindConn.Close()

> MyDataGrid.DataSource=DS.Tables("Customers").DefaultView
> MyDataGrid.DataBind()

> My stored procedure is :

> Create Procedure StoredProcedureName

> As

> Can anyone advise me ? for now i still getting the error which tell me the
> 'StoredProcedurName' wasn't recognized.

> Regards,

> Budhy SB



 
 
 

!! Help Binding A StoredProcedure record result to the Data Set and bind it to DataGrid

Post by Bill Andreozz » Sat, 29 Sep 2001 01:42:46


I forgot to show you the addition of parameters. - Notice that SQLGETPRODCAT is really a const string that is the actual name of the stored procedure defined somewhere else.
A sample of a function that would call this function is:

public bool GetProductCategory( int idCategory, ref DataGrid dg )

{

// Fill the parameter object

SqlCommand dbCmd = new SqlCommand();


return FillDataGrid( SQLGETPRODCAT, ref dbCmd, ref dg );

Quote:}// End of GetProductCategory

thanks - bill

> Hi All,

> Can anyone help me, i was trying to set my record result which got from
> executing one storedProcedure by the SQLDataAdapter, and
> then the result will set to the Data Set Object which also will be bind
> together with DataGrid.

> Is it possible ? My problem is i can't set the fill argument as a
> storedprocedure which has the parameter

> Dim nwindConn As SqlConnection = New SqlConnection("Data
> Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")


> nwindConn)
> selectCMD.CommandTimeout = 30


> SqlDbType.NChar, 5))

> Request("txCustomerID")

> Dim custDA As SqlDataAdapter = New SqlDataAdapter

> custDA.SelectCommand = selectCMD

> nwindConn.Open()

> Dim custDS As DataSet = New DataSet
> custDA.Fill(custDS, "Customers")
> nwindConn.Close()

> MyDataGrid.DataSource=DS.Tables("Customers").DefaultView
> MyDataGrid.DataBind()

> My stored procedure is :

> Create Procedure StoredProcedureName

> As

> Can anyone advise me ? for now i still getting the error which tell me the
> 'StoredProcedurName' wasn't recognized.

> Regards,

> Budhy SB


 
 
 

!! Help Binding A StoredProcedure record result to the Data Set and bind it to DataGrid

Post by budh » Tue, 02 Oct 2001 11:48:43


Thank's to all the best, it fix now :)

Regards,

Budhy SB

----- Original Message -----

Newsgroups: microsoft.public.dotnet.framework.aspnet.mobile
Sent: Friday, September 28, 2001 6:35 AM
Subject: RE: !! Help Binding A StoredProcedure record result to the Data Set
and bind it to DataGrid

> Budhy,
> There are four changes that I made to the code below to get this to work.
> The first is when you create the command remove the parameter since you
> will append this later in code.
> Dim selectCMD As SqlCommand = New SqlCommand("StoredProcedureName",
> nwindConn)

> The second is add code to define what type of command this is:
> selectCMD.CommandType = CommandType.StoredProcedure

> The third is to change how you create the parameters (omit the
> "SelectCommand"):

> SqlDbType.NChar, 5))

> Request("txCustomerID")

> The fourth is that there is a syntax error when you set the datasource, it
> should be:
> MyDataGrid.DataSource = custDS.Tables("Customers").DefaultView

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.

> Thanks,
> Jeremy Bostron
> Microsoft Beta Support
> --------------------


> Subject: !! Help Binding A StoredProcedure record result to the Data Set
> and bind it to DataGrid
> Date: Thu, 27 Sep 2001 15:10:02 +0700
> Lines: 62
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2462.0000
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000

> Newsgroups:

microsoft.public.dotnet.framework.aspnet.mobile,microsoft.public.dotnet.fram
> ework.aspnet
> NNTP-Posting-Host: ip71-2.cbn.net.id 202.158.71.2
> Path: cppssbbsa01.microsoft.com!tkmsftngp01!tkmsftngp04
> Xref: cppssbbsa01.microsoft.com
> microsoft.public.dotnet.framework.aspnet.mobile:1699
> microsoft.public.dotnet.framework.aspnet:13493
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.mobile

> Hi All,

> Can anyone help me, i was trying to set my record result which got from
> executing one storedProcedure by the SQLDataAdapter, and
> then the result will set to the Data Set Object which also will be bind
> together with DataGrid.

> Is it possible ? My problem is i can't set the fill argument as a
> storedprocedure which has the parameter

> Dim nwindConn As SqlConnection = New SqlConnection("Data
> Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")


> nwindConn)
> selectCMD.CommandTimeout = 30


> SqlDbType.NChar, 5))

> Request("txCustomerID")

> Dim custDA As SqlDataAdapter = New SqlDataAdapter

> custDA.SelectCommand = selectCMD

> nwindConn.Open()

> Dim custDS As DataSet = New DataSet
> custDA.Fill(custDS, "Customers")
> nwindConn.Close()

> MyDataGrid.DataSource=DS.Tables("Customers").DefaultView
> MyDataGrid.DataBind()

> My stored procedure is :

> Create Procedure StoredProcedureName

> As

> Can anyone advise me ? for now i still getting the error which tell me the
> 'StoredProcedurName' wasn't recognized.

> Regards,

> Budhy SB


 
 
 

1. Need help with binding SQL query results & then displaying those results.

I am new to asp.net and have been having some trouble binding my SQL
query results and displaying those results. Any tips you might have
would be greatly appreciated. Thanks :)

Sample code::





<script runat="server">

 Sub Page_Load(Sender As Object, E As EventArgs)

  Dim myDBaseName As String = "myDatabase"
  Dim myServer AS String = "sql2"

  Dim connectionString As New SqlConnection("server=" & myServer & ";
        trusted_connection=true; Database=" & myDBaseName & "")
        Dim myCommand As New SqlDataAdapter("SELECT ID FROM TICKET_ID
WHERE (claim = 'N');", connectionString)

        Dim ds As New DataSet()
        myCommand.Fill(ds, "TICKET_ID")

        MyRepeater.DataSource = ds.Tables("ID").DefaultView
        MyRepeater.DataBind()

 End Sub

</script>

<head>
</head>
<body bottommargin="0" bgcolor="#ffffff" leftmargin="0" topmargin="0"
rightmargin="0" marginwidth="0" marginheight="0" onload="Page_Load)">

         <ASP:Repeater id="myRepeater" runat="server">
 <ItemTemplate>
  <%# DataBinder.Eval(Container.DataItem, "ID") %>
 </ItemTemplate>
</ASP:Repeater>

</body>
</html>

2. SEARCHING PICASSO II OWNERS

3. DataGrid/C# : How to access DataGrid data(set/source) from other methods after binding?

4. VC7 internal compiler error in IDL complier generated files

5. Inserting new Data into Bound Datagrid + Bound Textboxes (Master/Detail) in WinForm

6. Rose: composite aggregation

7. Datagrid Bound Column Text vs Bound Data

8. Diabling Mouse Temporarily: Help

9. Data Binding within Data Bound Controls.

10. How to set data binding of treeView control to access data?

11. Need help desperately with datagrid and binding multiple data values to a single cell

12. Help with data bound to dataGrid

13. binding the results of an xml transform into a datagrid