Reply
asp.net db connection
Old 04-07-2008, 04:04 PM asp.net db connection
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
I am trying to take the asp.net plunge. Not as easy as asp...!

A couple of questions... If I may?


Something I do not understand. Declaring the database does so through showing where the actual database resides. I am used to using the DSN. What is the difference?

Do I still need to set the database with a ODBC Connection on the server?

I also read on one of the tutorials about setting up a Virtual Server. I tried this and still found no success...

I'm just not understanding the logic as easily as I did with asp(NOT NET)



Here is the connnection string I am trying, What AM I missing?

Code:
<script language="VB" runat="server">
sub Page_Load
dim dbconn, sql, dbcomm, dbread, tbl_VIP_Surv
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("marketing1.mdb"))
dbconn.Open()
sql="SELECT * FROM tbl_VIP_Surv"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
tbl_VIP_Surv.DataSource=dbread
tbl_VIP_Surv.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script>
Here is the error:
Object variable or With block variable not set.

Code:
Line 24: dbcomm=New OleDbCommand(sql,dbconn)
Line 25: dbread=dbcomm.ExecuteReader()
Line 26: tbl_VIP_Surv.DataSource=dbread
Line 27: tbl_VIP_Surv.DataBind()
Line 28: dbread.Close()
Thanks for any help..

Chip

Last edited by ChipJohns : 04-07-2008 at 04:06 PM.
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Sponsored Links (We share ad revenue):
 
Old 04-07-2008, 07:46 PM Re: asp.net db connection
Learning Newbie's Avatar
Moderator

Latest Blog Post:
My Favorite Isaac Asimov Story
Posts: 4,068
Name: John Alexander
Quote:
Originally Posted by ChipJohns View Post
Something I do not understand. Declaring the database does so through showing where the actual database resides. I am used to using the DSN. What is the difference?
You declare a database connection, and when that's done, you're reserving an area in memory the object will live in.

You populate your connection object with a "connection string". This can be the path to the database (server=x; database=y; uid=z; etc) or it can point at a DSN which then points at the database, if you prefer. I think your connection string would just be Data Source=DSN in that case.

The error you printed below sounds like a VB Script aka ASP error. But given the message and the code line

Line 26: tbl_VIP_Surv.DataSource=dbread

I'd say your tblVIPSurv hasn't been instantiated. In other words, you've declared the variable, but never gave it a value.

Dim tblVIPSurv As Object
tblVIPSurv = new Some_Class_Name()
__________________
HungarianNotation is the last resort of scoundrels. Why not the first resort? That's where it counts!
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 06:06 AM Re: asp.net db connection
Junior Talker

Posts: 3
Hi,

I'm a C# developer but i think i can see the problem...

dbread=dbcomm.ExecuteReader()
tbl_VIP_Surv.DataSource=dbread
your trying to bind something to a datareader...which as far as i'm aware can't be done.

instead, declare a datatable and a data adapter and use that to bind.

In C# it'd be....

Code:
        OleDbConnection Connection = new OleDbConnection(connString);

        DataTable dt = new DataTable();

        string Sql = "SELECT * FROM tbl_VIP_Surv";

        try
        {
            Connection.Open();
            OleDbCommand Command = new OleDbCommand(Sql, Connection);
            OleDbDataAdapter adapt = new OleDbDataAdapter(Command);
            adapt.Fill(dt);
        }
        finally
        {
            Connection.Close();
        }

        tbl_VIP_Surv.DataSource = dt;
        tbl_VIP_Surv.DataBind();
Hope this helps a bit
seanxe is offline
Reply With Quote
View Public Profile
 
Old 04-11-2008, 12:06 PM Re: asp.net db connection
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
Thanks,

I've been out for a while...

I will try this and get back... Thanks
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to asp.net db connection
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.14514 seconds with 14 queries