Forum Home
Press F1
 
Thread ID: 45926 2004-06-07 08:05:00 Anyone know ASP.net? george12 (7) Press F1
Post ID Timestamp Content User
242480 2004-06-07 08:05:00 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 (7)
242481 2004-06-07 08:07:00 BTW the Response.Write(QueryString) is just for debugging george12 (7)
1