I want a help in adding data to a database using asp! PLease help!!!?

dfina_amir

New member
Actually I want to use a textarea, in that textarea I want to put name and his/her age separated by a comma for example [Amir,17]. On hitting the submit button, the data [Amir] should be stored in name field of the Ms access table and [17] should be stored in age field of the same table. Is it possible to saparate two data by a comma? If yes then how?
 
Hello,

For the below code samples I will assume that you are using VB for your ASP code behind files.

With that being said, here is the code to connect to an access database:
Connecting to an access database:


Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb;Jet OLEDB:Database Password=password")
Dim Command As New OleDb.OleDbCommand

Connection.Open() 'open up a connection to the database
Command.Connection = Connection


Getting the values of multiple rows:



Dim ds As New Dataset
Dim da As New OleDb.OleDbDataAdapter
Dim row As System.Data.DataRow
Dim Count As Integer

da.SelectCommand = New OleDb.OleDbCommand("SELECT *", Connection)
da.Fill(ds, "Table") 'Fill the dataset, ds, with the above SELECT statement

Count = ds.Tables("Table").Rows.Count
Dim Values(Count) As String

While Count > -1
row = ds.Tables("Table").Rows.Item(Count)
Values(Count) = row.Item(0)
Count = Count - 1
End While




Executing a query with just one result:

Dim People As String

MyCommand.CommandText = "SELECT `People` FROM `Rooms` WHERE ID = 1"
People = MyCommand.ExecuteScalar()


Updating the database:

MyCommand.CommandText = "UPDATE `Users` SET `Address` = '431 Cat Ave.' WHERE `ID` = 3"
MyCommand.ExecuteNonQuery()

and in the end never forget:

Connection.close()
 
Back
Top