need help with add data to database in web application

rayda

New member
Joined
Jun 29, 2010
Messages
2
Programming Experience
Beginner
hi there.
i m trying to write codes for new user to fill in the form, then the new data will into my database,however, my codes doesnt work, i cant figure out what's wrong with my codes.
below are my codes:
Imports System.Data.OleDb
Public Class NewUser
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnCreate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCreate.Click
Dim DBConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:/login_1.mdb")
Dim DBCmd As New OleDbCommand
' Dim DBAdap As New OleDbDataAdapter
' Dim DS As New DataSet
Try
DBCmd = New OleDbCommand("Insert Into NewUser(UserName,Password,Name,Email) Values (@UserName, @Password, @Name, @Email)", DBConn)

Dim paramusername As New OleDbParameter("@UserName", OleDbType.VarChar, 50)
paramusername.Value = txtNUser
DBCmd.Parameters.Add(paramusername)

Dim parampassword As New OleDbParameter("@Password", OleDbType.VarChar, 50)
parampassword.Value = txtNPwd
DBCmd.Parameters.Add(parampassword)

Dim paramname As New OleDbParameter("@Name", OleDbType.VarChar, 50)
paramname.Value = txtName
DBCmd.Parameters.Add(paramname)

Dim paramemail As New OleDbParameter("@Email", OleDbType.VarChar, 50)
paramemail.Value = txtEmail
DBCmd.Parameters.Add(paramemail)

'DBCmd.Parameters.Add("@UserName", OleDbType.VarChar).Value = txtNUser.Text
'DBCmd.Parameters.Add("@Password", OleDbType.VarChar).Value = txtNPwd.Text
'DBCmd.Parameters.Add("@Name", OleDbType.VarChar).Value = txtName.Text
'DBCmd.Parameters.Add("@Email", OleDbType.VarChar).Value = txtEmail.Text

DBConn.Open()
DBCmd.ExecuteNonQuery()
Response.Write("Updated")
Catch exp As Exception
Response.Write("Die")
End Try

DBCmd.Dispose()
DBConn.Close()
DBConn = Nothing
End Sub
End Class

there is no error encounter, however,the adding is failed and no new data can be add in.
anyone know what's wrong with my codes?..

thank you.
 
Back
Top