By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

help me debug

P: 33
help 'e debug

I wrote the below code to input new data from name and address textbox of a form to microsoft access but there are alot of error. the name of the table in the access is Hotel and the the fields are HotelName and HotelAddress . Please can somebody help me and debug. i used

Note: almost all the line is underlined with red line indicating incorrect declaration and so on. please help me debuge. i know is also possible you set OleDb connection and OleDbAdapter and then write a few line code to input data into database. how do i write the code. please help me

Expand|Select|Wrap|Line Numbers
  1. Private Sub submitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim Objconn As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector  y|\ECBInvoicing.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
  5.         Objconn.Open()
  7.         ObjCmd = New SqlCommand("INSERT INTO hotel (HotelName, HotelAddress) VALUES (@HotelName, @HotelAddress)", Objconn)
  10.         ObjCmd.Parameters.Add("@HotelName", Data.SqlDbType.VarChar).Value = txtHotelname.Text
  11.         ObjCmd.Parameters.Add("@HotelAddress", Data.SqlDbType.VarChar).Value = txtHotelAddress.Text
  14.         ObjCmd.ExecuteNonQuery()
  17.         Objconn.Close 
  18.     End Sub
Jun 24 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 211
To query access database you should use System.Data.OleDb namespace
and create connection
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0 ;" +
" User Id=; Password=; Data Source="mdb file name")

Create command
OleDbCommand command = connection.CreateCommand()
command.CommandText = ""

Create DataReader
OleDbDataReader reader = command.ExecuteReader();

Jun 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.