fischadler
Programmer
Sounds simple. At least it was simple with classic ASP. I am now trying to switch to the supposedly better ASP.NET but I cannot make a simple database connection and retrieve the value of a field.
I have looked through several pages using Google and all of them tell me how to store the contents of a database table into a datagrid or a repeater. But all I want is to store the contents of a single field of a single record recordset into a string variable.
I found this sample code below but I keep getting an error:
I keep getting this error:
System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
at this line:
What am I doing wrong? Note that I am totally new to ASP.NET and I am switching to it from Classic ASP.
Is there any better way to just store the contents of the field in a variable?
-Fischadler
I have looked through several pages using Google and all of them tell me how to store the contents of a database table into a datagrid or a repeater. But all I want is to store the contents of a single field of a single record recordset into a string variable.
I found this sample code below but I keep getting an error:
Code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
sub Page_Load(sender as Object, e as EventArgs)
Dim connString as String
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("data.mdb")
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open() 'open the connection
'Specify our SQL statement
Dim strSQL as String = "SELECT NewsID, NewsDate, NewsTitle, NewsIntro, NewsDetails FROM News WHERE (((NewsID)=1000));"
'Create the Command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
' Set an OleDbDataReader to the command's results
Dim objDataReader as OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim str as string
While objDataReader.Read()
str = objDataReader("NewsTitle")
End While
Response.Write(str)
objDataReader.Close()
end sub
</script>
I keep getting this error:
System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
at this line:
Code:
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
What am I doing wrong? Note that I am totally new to ASP.NET and I am switching to it from Classic ASP.
Is there any better way to just store the contents of the field in a variable?
-Fischadler