Insert Data

  • Thread starter Thread starter Rafael Tejera
  • Start date Start date
R

Rafael Tejera

I'm new using visual basic, I'm programmer in visual foxpro and I want try
visual basic .net

I would like to know how i can insert data from a form using insert.

I already have 3 textbox in my form and a botton, only i need the code to
insert in my table which is Ms access.

I would like to use the insert command, please help me.


Rafael
 
Rafael,

You can use the Insert command, however mostly is used the dataset, a
datatable, a dataadapter and databinding with dotNet.

See this sample how the use of buttons and textboxes becomes than very
simple
http://www.windowsformsdatagridhelp.com/default.aspx?ID=c4832a2a-2b95-4ded-93d9-4deb7fa4a0b8

For the update you use the dataadapter.update
I see now that we have nothing for that on our website so that will be soon.

In fact it can go in general like this (for the first table in the dataset)
sample for the most part typed in this message so watch errors.
\\\
(imports system.data.oledb)

Dim Conn As New OleDbConnection("connectionstring")
Try
Dim da As New OleDbDataAdapter(sqlstring, Conn)
da.SelectCommand.CommandTimeout = 160
Dim cb As New OleDbCommandBuilder(da)
Bindingcontext(ds.Tables(0)).EndCurrentEdit
If ds.HasChanges Then
da.Update(ds.Tables(0))
End If
Catch ex As OleDbException
'procedures to Handlde the errors
Catch ex As Exception
'procedures to handle the errors
End Try
////
 
Rafael Tejera said:
I'm new using visual basic, I'm programmer in visual foxpro and I want try
visual basic .net

I would like to know how i can insert data from a form using insert.

I already have 3 textbox in my form and a botton, only i need the code to
insert in my table which is Ms access.

I would like to use the insert command, please help me.



http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaccessingdatawithadonet.asp
http://msdn.microsoft.com/library/en-us/vbcon/html/vboriWindowsFormsDataArchitecture.asp
http://msdn.microsoft.com/library/en-us/vbcon/html/vboriIntegratingDataVB.asp



Armin
 
This is my function for executing UPDATE, INSERT and DELETE commands on
a database. You just supply the SQL statement and the connection
string and then execute the function.

Public Function ExecDB(ByVal ExecuteQuery As String, ByVal
ConnectionString As String) As Boolean
' This function takes in a execute statement and a database
connection
' string and will execute the statement on the database and
report true/false
' if it executed properly or not

Try
Dim oleConn As New OleDbConnection(ConnectionString)
Dim oleCmd As New OleDbCommand(ExecuteQuery, oleConn)
oleCmd.Connection.Open()
oleCmd.ExecuteNonQuery()
oleConn.Close()
oleCmd.Dispose()
Return True
Catch ex As Exception
MessageBox.Show("Database Error:" & Chr(10) & ex.Message)
Return False
End Try
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top