how can i write in a database

  • Thread starter Thread starter belange
  • Start date Start date
B

belange

I try to create a little web application with c# and visual studio.net.
With this application, a student can reserved a computer station, the day
and the hour. I want to write these informations in an access database with
the student's user name.
I am a rookie, so how can i write in a database.
Thanks for your help.
 
Assuming the textboxes are txtUserName, txtDay, txtHour, the minimalist
approach is (The code here is Visual Basic .NET):

1. Create a table called Reservation
a) ReservationID autonumber
b) StudentName string
c) Day string
d) Hour string

2) The following will insert

'At top of form
Imports System.Data
Imports System.Data.OleDb


'In method
Dim sql As String = "INSERT INTO Reservation " & _
"(StudentName, Day, Hour) VALUES ('" &_
txtUserName.Text & "','" & txtDay.Text & _
"','" & txtHour.Text & "');"

Dim connString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\somepath\myDb.mdb;" & _
"User Id=admin;" & _
"Password="

'NOTE: sompath is path to MDB file
'NOTE: myDb.mdb is name of MDB file

Dim conn As New OleDbConnection(connString)
Dim cmd As New OleDbCommand(sql, conn)

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
conn.Dispose()

That is the basics. I would recommend picking up a good book on .NET before
getting much deeper.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
Cowboy (Gregory A. Beamer) said:
Assuming the textboxes are txtUserName, txtDay, txtHour, the minimalist
approach is (The code here is Visual Basic .NET):

Thanks a lot for your help, your answer is perfect,
it's just that I need, now I can try to program my web application.

See you
 
Back
Top