| | |
manipulate the data in the database
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 19
Reputation:
Solved Threads: 1
Hi I used the Data Source Configuration Wizard to connect to my access database, how do I write code to manipulate the data from the database? I read the book "Microsoft Visual Basic 208 step by step", it only teaches how to display data on the form. So how do I write the code so that I can input data and search if the database has this data at runtime?
Cheers,
Daniel
Cheers,
Daniel
•
•
Join Date: Jun 2009
Posts: 132
Reputation:
Solved Threads: 13
u need to use queries to insert data.
eg.
u begin with establishing a connection with the statement
dim oledbcon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\abc.accdb;Persist Security Info = false;")
u then open the connection using the statement
oledbcon.open
insert query
oledbcom.CommandText = ("INSERT INTO Customer (Company, Address, Telephone) values (?,?,?)")
oledbcom.Connection = oledbcon
adding the parameters.
each question mark in the above statement indicates a parameter.
Dim oledbparam As OleDb.OleDbParameter = _
oledbcom.Parameters.Add("@Company", OleDb.OleDbType.VarChar, 30)
oledbparam.Value = txtCompName.Text.Trim()
oledbparam = oledbcom.Parameters.Add("@Address", OleDb.OleDbType.VarChar, 80)
oledbparam.Value = txtAddress.Text.Trim
oledbparam = oledbcom.Parameters.Add("@Telephone", OleDb.OleDbType.VarChar, 15)
oledbparam.Value = txtContact.Text.Trim
execute the query
oledbcom.ExecuteNonQuery()
close the connection using
oledbcon.close
eg.
u begin with establishing a connection with the statement
dim oledbcon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\abc.accdb;Persist Security Info = false;")
u then open the connection using the statement
oledbcon.open
insert query
oledbcom.CommandText = ("INSERT INTO Customer (Company, Address, Telephone) values (?,?,?)")
oledbcom.Connection = oledbcon
adding the parameters.
each question mark in the above statement indicates a parameter.
Dim oledbparam As OleDb.OleDbParameter = _
oledbcom.Parameters.Add("@Company", OleDb.OleDbType.VarChar, 30)
oledbparam.Value = txtCompName.Text.Trim()
oledbparam = oledbcom.Parameters.Add("@Address", OleDb.OleDbType.VarChar, 80)
oledbparam.Value = txtAddress.Text.Trim
oledbparam = oledbcom.Parameters.Add("@Telephone", OleDb.OleDbType.VarChar, 15)
oledbparam.Value = txtContact.Text.Trim
execute the query
oledbcom.ExecuteNonQuery()
close the connection using
oledbcon.close
•
•
Join Date: Jun 2009
Posts: 19
Reputation:
Solved Threads: 1
This is my code. when I run it. there is nothing happen in my database1.mdb Could you please tell me the problem?
VB.NET Syntax (Toggle Plain Text)
'build access database connection Dim Conn As New OleDbConnection("provider = microsoft.jet.oledb.4.0;data source = D:\access\Database1.mdb;User ID = Admin;Password =;Persist Security Info = false") 'open database Conn.Open() 'insert query and select query, in this case I don't know if select query is needed, but visual studio return errors when I do fill dataset without the select command Dim insertSQl As String = "INSERT INTO tbl1(User, password) values (Dave, 123456)" Dim selectSQL As String = "SELECT * from tbl1" Dim adapter As New OleDbDataAdapter() Dim selectcmd As New OleDbCommand(selectSQL, Conn) adapter.SelectCommand = selectcmd Dim insertcmd As New OleDbCommand(insertSQl, Conn) adapter.InsertCommand = insertcmd 'I don't know what the parameters do in the code insertcmd.Parameters.Add("@User", OleDbType.VarChar, 30).Value = "Dave" insertcmd.Parameters.Add("@password", OleDbType.VarChar, 30).Value = "123456" Dim User As New DataSet adapter.Fill(User, "User") Dim password As New DataSet adapter.Fill(password, "password") Conn.Close()
Last edited by hjdaniel.sun; Jul 10th, 2009 at 7:02 am. Reason: I didn't write the code nicely
•
•
Join Date: Jun 2009
Posts: 132
Reputation:
Solved Threads: 13
regarding ur parameter question
"?" indicates that this is the parameter. it is just any value.
but the value is decided by some other control.
eg.
this is the normal query u require in the database
but if u wish to write this statement in .net where the name is taken from a textbox.
the question mark indicates that the value is to be taken from some control.
assign a value to it.
"?" indicates that this is the parameter. it is just any value.
but the value is decided by some other control.
eg.
VB.NET Syntax (Toggle Plain Text)
insert into customer values "abc"
but if u wish to write this statement in .net where the name is taken from a textbox.
VB.NET Syntax (Toggle Plain Text)
insert into customer ?
assign a value to it.
hjdaniel.sun,
You are struggling with programming. Keep one thing in mind, we will help you in case you have a little problem. We will try out best but my suggestion to you that - Don't waste your time. Get some books - Database, .net framework, VB.NET language (OOP. .NET programming requires fundamental knowledge of Object-Oriented paradigm.
•
•
•
•
manipulate the data in the database
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- How to insert data into database? (JSP)
- inser data into database (JSP)
- Populate data from database into JList (Java)
- view and edit data from database (VB.NET)
- Unable to insert data into database. (MySQL)
- how VB get data from database randomly (Visual Basic 4 / 5 / 6)
- Login and retrieve user data from database (ASP.NET)
- php wont submit data into the database (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Upload file via PHP upload form.
- Next Thread: Receiving data from modem with MScomm
| Thread Tools | Search this Thread |
.net .net2008 2008 access advanced application array basic beginner browser button buttons center click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function generatetags html images input intel internet listview map mobile module monitor msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms winsock wpf wrapingcode xml year






