Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Creating a recordset in ASP.NET
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 14 April 2005 :  12:19:56  Show Profile
Try and use the .NET data providers System.Data.SqlClient and steer clear of recordsets, use DataReader, DataSet, DataTable etc

The UK MkIVs Forum
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 14 April 2005 :  12:31:20  Show Profile
Ay, as you can see above, that's the direction I've gone in thanks to Ghost - just having trouble reading from the datareader object now.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

Ghostnetworks
New Member

95 Posts

Posted - 14 April 2005 :  12:50:12  Show Profile  Visit Ghostnetworks's Homepage
In context, your code should look like this..

dim objConn as new odbcconnection("driver=MySQL;server=localhost;uid=username;pwd=password;database=database;")
dim objComm as new odbccommand("SELECT FIELDS FROM TABLE WHERE FIELD=VALUE",objConn)
objConn.open()
dim rs as odbcdatareader=objComm.executereader()
dim strString as string

While rs.Read()
	strString = rs.GetString(0)
End While

rs.close()
objConn.close()


I've realized, in the longer run, it's easier to delcare a field as a name instead of the row number..
As in..
objDataReader("MyField").ToString()
..Because it's easier to remember what I'm calling and storing.
The numbers will do fine if it's a small query, but for longer returns it may be confusing to keep track of all the returned row numbers. Unless I'm on my third cup of coffee, I can't do it

Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 14 April 2005 :  13:00:07  Show Profile
Cheers, Ghost; will give that a whirl in the morn' let you know how I get on. What I'm working on is a small query, by the way, only returning one field from one record.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 15 April 2005 :  07:11:30  Show Profile
Huzzah! Finally got it working Many thanks, Ghost I'd missed the While statement when copying from that page on MSDN, probably a good indication that my upcoming holidays are long overdue (first in 2 years!) Anyway, for wnyone else who may happen across this topic, this is what I have now:
<%@import namespace="system.data.odbc"%>
dim objConn as new odbcconnection("driver=MySQL;server=localhost;uid=username;pwd=password;database=database;")
dim objComm as new odbccommand("SELECT FIELDS FROM TABLE WHERE FIELD=VALUE",objConn)
objConn.open()
dim rs as odbcdatareader=objComm.executereader()
dim strString as string
while rs.read()
	strString=rs.getstring(0)
end while
rs.close()
objConn.close()
Nearly finished my thumbnail generator, now, just need to figure out how to add some transparent pixels to the edges of those thumbnails that are less than 100 square pixels, but that can wait 'eil I get back.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

Etymon
Advanced Member

United States
2393 Posts

Posted - 29 April 2005 :  06:19:57  Show Profile  Visit Etymon's Homepage
Hi Shaggy,

I'm trying to convert this:

	strSql = "SELECT " & strTablePrefix & "TOPICS.T_STATUS " & strTablePrefix & "TOPICS.T_SUBJECT" & strTablePrefix & "TOPICS.T_DATE "
	strSql = strSql & "FROM " & strTablePrefix & "TOPICS "
	strSql = strSql & "WHERE " & strTablePrefix & "TOPICS.TOPIC_ID = " & topicid

	set rs = my_Conn.Execute(strSql)

	topicstatus = rs("T_STATUS")
	topicsubject = rs("T_SUBJECT")	
	topicdate = rs("T_DATE")

	rs.close
	set rs = nothing


into your code. I came up with this below:

<%@import namespace="system.data.odbc"%>
dim objConn as new odbcconnection("driver=MySQL;server=localhost;uid=username;pwd=password;database=database;")
dim objComm as new odbccommand("SELECT FIELDS FROM TOPICS WHERE TOPIC_ID=" & topicid & ",objConn)
objConn.open()
dim rs as odbcdatareader=objComm.executereader()
dim strString as string
while rs.read()
	strString=rs.getstring(0)
end while
rs.close()
objConn.close()


----------------------

How do I convert:

	topicstatus = rs("T_STATUS")
	topicsubject = rs("T_SUBJECT")	
	topicdate = rs("T_DATE")


to what I need?

Thank you for posting this discussion.


Cheers,

Etymon
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 29 April 2005 :  06:28:27  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
I'm at work at the moment & don't have the exact info to hand but its something like this;

topicstatus = odbcdatareader.GetValue("T_STATUS")
topicsubject = odbcdatareader.GetString("T_SUBJECT")
topicdate = odbcdatareader.GetValue("T_DATE")

You can also use something like this

topicstatus = odbcdatareader.GetValue(0)
topicsubject = odbcdatareader.GetString(1)
topicdate = odbcdatareader.GetValue(2).tostring

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 29 April 2005 :  06:46:55  Show Profile
What Podge posted above should be contained within the while statement in my last post, where I have rs.getstring(0). To place Podge's examples within that code, you'd need to change odbcdatareader to rs or whatever name you give to your data reader object.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

Etymon
Advanced Member

United States
2393 Posts

Posted - 29 April 2005 :  07:03:38  Show Profile  Visit Etymon's Homepage
Thanks guys,

I'll give it a try.
Go to Top of Page

Etymon
Advanced Member

United States
2393 Posts

Posted - 29 April 2005 :  07:26:34  Show Profile  Visit Etymon's Homepage
Hmmm ....

Now how do I write the variable topicstatus into my code?

Response.Write topicstatus
doesn't seem to work.

Any links to doing this kind of thing is fine too.

Etymon
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 29 April 2005 :  07:36:27  Show Profile
As far as I know, you have to have parentheses when calling a function or subroutine in .NET, not like classic ASP where they could be left out in certain situations. So you need:

response.write(topicstatus)


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

Etymon
Advanced Member

United States
2393 Posts

Posted - 29 April 2005 :  07:42:05  Show Profile  Visit Etymon's Homepage
Ah, ok.

Um, how about this:

" & topicstatus & "


Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 29 April 2005 :  07:42:39  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Maybe topicstatus is empty ?

You shoudl really be using try - catch blocks to see if there is an error when retrieving the row.

e.g.

try
'do something e.g. datareader stuff
catch ex as Exception
response.write ex.toString
finally
' even if errors execute code
end try

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.62 seconds. Powered By: Snitz Forums 2000 Version 3.4.07