PDA

View Full Version : Anyone know ASP.net?



george12
07-06-2004, 08:05 PM
I am trying to create a function to write a single value to a field in a table of a database (users.mdb), so that I can execute commands such as:

SaveDataField("John","Email","john@jgih.com")

When I run this script, there are no errors, but the database does not change.

Public Function SaveDataField(UserName,Field,Value)
Dim MyConn as OleDbConnection
Dim ConnStr as String
ConnStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\db\Users.mdb"
MyConn= new OleDbConnection(ConnStr)
MyConn.Open
Dim queryString As String = "UPDATE Users SET '" & Field & "' = '" & Value & "' WHERE UserName = '" & UserName & "'"
response.write(querystring)
Dim dbCommand As OleDbCommand = New OleDbCommand(querystring,MyConn)
MyConn.Close
End Function

If it helps, I run the ASP.net framework, latest version. The function I use to read a value is:


Public Function GetUserData(UserName,Field) As String
Dim MyConn as OleDbConnection
Dim ConnStr as String
Dim ResultVal as String
ConnStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\db\Users.mdb"
MyConn= new OleDbConnection(ConnStr)
MyConn.Open
Dim queryString As String = "SELECT [Users].[" & Field & "] FROM [Users] WHERE ([Users].[UserName] = '" & UserName & "')"
Dim dbCommand As OleDbCommand = New OleDbCommand(querystring,MyConn)
ResultVal = dbCommand.ExecuteScalar()
MyConn.Close
Return ResultVal
End Function

I would write, say,
Response.Write(GetUserData("John","Email")) - this works fine.

Can anyone tell me why this happens, and how to fix it?

george12
07-06-2004, 08:07 PM
BTW the Response.Write(QueryString) is just for debugging