Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2006, 11:30 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Public Class Data
    Public Function ProjMain() As DataSet
        Dim objData As ConnectSql
        Dim objcom As SqlCommand
        Try
            objData = New ConnectSql
            objData.CreateCommand(objcom, CommandType.StoredProcedure, "ProjMain")
            ProjMain = objData.CreateDataset("Data", objcom)
            objcom.ExecuteReader()
        Catch ex As Exception
        End Try
    End Function
end class

venkat

 
Old December 11th, 2006, 11:36 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you remove your Try Catch block this code is almost certainly throwing an error. You never call your connection string from your webconfig file nor do you return anything. The code your provided executes as a method, not a function.

DataTable getDataTable()
{
 DataTable tempDT = new DataTable();
 daSql = new SqlDataAdapter();
 sqlCmd = new SqlCommand();
 sqlConn = new SqlConnection();
 daSql.SelectCommand = sqlCmd;
 sqlCmd.Connection = sqlConn;
 sqlConn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionStrin g");
 sqlCmd.CommandText = [SQL Statement];
 daSql.Fill(tempDT);
 return tempDT;
}

That code returns a datatable.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 12th, 2006, 03:40 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm beginner in ASP.net pl. explain ur code

i enter ur code

but error : declaration expected


 
Old December 12th, 2006, 03:57 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just try the code below, it should work for you:

Dim sConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
            Dim sQuery As String = "spTest"

            sConn.Open()
            Dim sqlCmd As SqlCommand = New SqlCommand(sQuery,sConn)
            sqlCmd.CommandType = CommandType.StoredProcedure
            Dim da As SqlDataAdapter = New SqlDataAdapter(sqlCmd)
            Dim ds As DataSet = New DataSet()
            da.Fill(ds)

            DataGrid1.DataSource = ds
            DataGrid1.DataBind()
            sConn.Close()

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old December 12th, 2006, 04:07 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mike, where is put ur code

 
Old December 12th, 2006, 04:28 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Friend,

Don't mind, I guess first you need to study some programming basics, and then move to .net.

Anyways, the code I gave you can be put wherever you wish to bind the datagrid, say on page_load.

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old December 12th, 2006, 09:27 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The declartaion error that my code throws is because, in my code that I supplied, I do not declare my Sql objects in that function; I thought it was obvious that one would need to delare the objects to use that function.

I understand that you are a beginner to .NET and I applaud you for wanting to learn, however, I agree with Mike here. It seems that you need to study some programming basics before you start in on hard core .NET programming. I suggest picking up a book or reading any of the various resources that come up on google to get you started.


-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 12th, 2006, 10:22 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike & Dparson ur guidance


 
Old December 14th, 2006, 03:55 AM
Registered User
 
Join Date: Dec 2006
Location: Pune, MH, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to smashingpravin Send a message via Yahoo to smashingpravin
Default

Please send us code dat u have wrote for binding data

ragards

Pravin Patil
 
Old December 14th, 2006, 04:06 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dim sConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
            Dim sQuery As String = "spTest"

            sConn.Open()
            Dim sqlCmd As SqlCommand = New SqlCommand(sQuery,sConn)
            sqlCmd.CommandType = CommandType.StoredProcedure
            Dim da As SqlDataAdapter = New SqlDataAdapter(sqlCmd)
            Dim ds As DataSet = New DataSet()
            da.Fill(ds)

            DataGrid1.DataSource = ds
            DataGrid1.DataBind()
            sConn.Close()

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.




Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 3.5 answers in Professional ASP.NET 3.5 jminatel ASP.NET 3.5 Professionals 1 August 22nd, 2011 07:34 AM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
Database diagram in .net using asp.net,c#.net scotttiger ADO.NET 2 February 16th, 2005 01:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.