0

hye,

i need help about asp.net..i new in this language. so i don't know how to connect database from ms access to asp.net and submit button.

the situation : when the user click on submit button, the data that they fill in will insert in database.

7
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by dbeura
0

first add a namespace to your form for vb.net

imports System.Data.OledDb
//then on button click event write this code
dim con as new OleDbConnection
con.ConectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;""
Con.open()\\access.mdb is my databasename
dim str as string
try
str="INsert into [table] values ('hi')"
dim cmd=new sqlCommand(str,con)
cmd.ExequteNonquery
 Msgbox ("Recored inserted")
Catch ex as Exception
Mesgbox (ex.Message)
Finally
cmd=nothing
con.close
end try
1

To connect MS access database in asp.net put following code in your project web.config file <connectionstring> tag.

<connectionStrings> <add name="myconnection"

connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|db1.mdb"
providerName="System.Data.OleDb"></add>
</connectionStrings>

Edited by searchec: n/a

-1

hi izzatikhalid,

here is the code:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;")
Dim str="insert into emp values('"& txtName &"','"& txtPassword &"','"& txtAddress &"')"
con.Open()
Dim cmd = New OleDbCommand(str,con)
cmd.executeNonQuery()
con.Close()
End Sub

1. In above example you can put your fielsd name in txtname, txtpassword etc..
2. just change the Data Source="your ms acces table path"
Do write if have prob
Happy coding

0

okkkkkkkkkkkkkkkkkkkkkkk

To connect MS access database in asp.net put following code in your project web.config file <connectionstring> tag.

<connectionStrings> <add name="myconnection"

connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|db1.mdb"
providerName="System.Data.OleDb"></add>
</connectionStrings>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.