Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert/Update Access from .NET webform

Status
Not open for further replies.

DWhitt

Programmer
Jan 28, 2002
3
US
Hi,

I'm very new to web programming and am trying to insert/update records to an access db via a webform. Use the form from 'HowToBuildAWebDataEntryApp' .NET Framework example as a guide in building my WebForm, except using Access 2000. When I do a 'Build & Browse' everything seems to go OK - in other words, No Errors generated, just the DB is never updated?? Following is some of my code:

Protected Const MSDE_CONNECTION_STRING As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\File Databases\WebKB.mdb"

Private Sub SaveNode()
Dim strSQL As String

If btnSaveNode.CommandArgument = "Add" Then
strSQL = _
"INSERT INTO Nodes (NodeID,Title) " & _
"VALUES (@NodeID,@Title)"
Else
strSQL = _
"UPDATE Nodes " & _
"SET Title = @Title, " & _
" NodeID = @NodeID " & _
"WHERE KeyID = @KeyID"
End If

Dim scnnNodes As New OleDbConnection(MSDE_CONNECTION_STRING)
Dim scmd As New OleDbCommand(strSQL, scnnNodes)

' Add all the required SQL parameters.
With scmd.Parameters
If btnSaveNode.CommandArgument <> &quot;Add&quot; Then
.Add(New OleDbParameter(&quot;@KeyID&quot;, _
OleDbType.Integer)).Value = _
CInt(grdNodes.DataKeys(grdNodes.SelectedIndex).ToString)
End If
.Add(New OleDbParameter(&quot;@Title&quot;, _
OleDbType.VarChar, 50)).Value = txtTitle.Text
.Add(New OleDbParameter(&quot;@NodeID&quot;, _
OleDbType.Integer)).Value = CInt(txtNodeID.Text)
End With

Try
scnnNodes.Open()
scmd.ExecuteNonQuery()

Cache.Remove(&quot;dvNodes&quot;)
BindNodesGrid()

strMsg = &quot;Main Node successfully saved to the database.&quot;
pnlNode.Visible = False
txtNodeID.Visible = False
txtTitle.Visible = False
btnSaveNode.Visible = False
Catch exp As Exception
strErrorMsg = &quot;Database error! Main Node not saved to the &quot; & _
&quot;database. Error message: &quot; & exp.Message
Finally
scnnNodes.Close()
End Try

End Sub

Like I said, I'm brand new to Web programming - mostly work in FoxPro. Any help greatly appreciated. Can't seem to get around this problem.

TIA,
Dave Whitt
 
try removing:

Catch exp As Exception
strErrorMsg = &quot;Database error! Main Node not saved to the &quot; & _
&quot;database. Error message: &quot; & exp.Message


...to see if any errors arise.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top