I have been trying to create a form to put data into a access database. I had the web host set up a ODBC connection for me. I use web matrix wizard to create the code and changed the connection string for the ODBC connection. I know I have to change a few more things but am not sure what to change.
here is the code:
Function work1() As System.Data.DataSet
dim objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "dsn=crf"
objConn.Open
Dim queryString As String = "SELECT [requests].* FROM [requests]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = objconn
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Function work2(ByVal name As String, ByVal company As String, ByVal street0 As String, ByVal street1 As String, ByVal city As String, ByVal state As String, ByVal zip As String) As Integer
dim objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "dsn=crf"
objConn.Open
Dim queryString As String = "INSERT INTO [requests] ([name], [company], [street0], [street1], [city], [state],"& _
" [zip]) VALUES (@name, @company, @street0, @street1, @city, @state, @zip)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = objconn
Dim dbParam_name As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_name.ParameterName = "@name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_name)
Dim dbParam_company As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_company.ParameterName = "@company"
dbParam_company.Value = company
dbParam_company.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_company)
Dim dbParam_street0 As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_street0.ParameterName = "@street0"
dbParam_street0.Value = street0
dbParam_street0.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_street0)
Dim dbParam_street1 As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_street1.ParameterName = "@street1"
dbParam_street1.Value = street1
dbParam_street1.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_street1)
Dim dbParam_city As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_city.ParameterName = "@city"
dbParam_city.Value = city
dbParam_city.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_city)
Dim dbParam_state As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_state.ParameterName = "@state"
dbParam_state.Value = state
dbParam_state.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_state)
Dim dbParam_zip As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_zip.ParameterName = "@zip"
dbParam_zip.Value = zip
dbParam_zip.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_zip)
Dim rowsAffected As Integer = 0
objconn.open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch
msgLabel.Text = "Database Error"
msgLabel.Visible = true
Finally
objconn.Close
End Try
Return rowsAffected
End Function' Insert page code here
Sub submit_Click(sender As Object, e As EventArgs)
If tname.Text = "" Or tcompany.Text = "" Or tstreet0.Text = "" Or tcity.Text = "" Or tstate.text = "" Or tzip.text = "" Then
msgLabel.Text = "One or more fields are empty. <br>Please complete all fields."
msgLabel.Visible = true
ElseIf work2(tname.Text, tcompany.Text, tstreet0.text, tstreet1.text, tcity.Text, tstate.text, tzip.text) > 0 Then
msgLabel.Text = tname.Text & " was added successfully"
msgLabel.Visible = True
End If
End Sub
Any comments would be a big help as creating web pages is not my main job. Thank You.