Adding row to table

B

Bonzol

Hi there,

VB 2003 1.1 Access Database, oledb, Windows Application

I've been trying this for 3 days straight now and CANNOT get this to
work, im about to go insane because it is soo simple. All I want to do
is insert a new row !

I have 1 table 'People'

In that table I have "Name" and "LastName" Name as primary Key."

my adapter is called OleDbDataAdapter1
my connection is called OleDbConnection1
and I have a dataset called DataSet11

my connection is

"Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""C:\Documents and
Settings\Pig\Desktop\New Folder\TEST" & _
".mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:Syste" & _
"m database=;Jet OLEDB:SFP=False;persist security
info=False;Extended Properties=" & _
";Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System D" & _
"atabase=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Wit" & _
"hout Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk
Transactions=1""

if anyone wants that.


On my form I have 2 text boxes

"txtname" and "txtlastname"
I also have a button "Button1"

All I want is for someone to put something in those two text boxes,,
press the button and for it to add a new Person with those 2 strings.

So they press the button and it adds a new row to the table, so like
adding a new person.


Can someone just tell me/show me how to do this, I'm having soo much
trouble, since I have asked about 50 people and tried about 50 differnt
ways and nothing works

PLEASE HELP ME.

thanx in advance
 
C

Cor Ligthert [MVP]

Bonzol,

You were writing this in the thread where I asked why you not was using the
code from GhostAIk had given you.

This was your answer.
yeah, I had a problem with it, and am waiting a reply in that other thread

What help do you want if you not tries what somebody gives you as
suggestion?

It was nice code for an insert in the way your question is asked.

Cor
 
B

Bonzol

As I said up the top, I have tried 50 peoples code.

I couldnt get his code to work.
 
B

Bonzol

cor,, with regards to his code,

Dim tConnection As SqlConnection = New
SqlConnection(yourConnectionStringHere)
Dim tCommand As SqlCommand = New SqlCommand

how do I reformat that for an oledb database?
 
B

Bonzol

I have tried

' Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Documents and Settings\Pig\Desktop\New Folder\TEST.mdb;User
Id=admin;Password=;"
' Dim tConnection As New OleDb.OleDbConnection(Conn)
' Dim tCommand As New OleDb.OleDbCommand

but then that stops half the other code from working, since it was
reffering to SQL and now is not.
 
B

Bonzol

ok, finally got it for anyone else who wants to know also.
Some guy on another forum helped. Cheers anyway

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click


Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Documents and Settings\Pig\Desktop\New Folder\TEST.mdb;User
Id=admin;Password=;"
Dim tConnection As New OleDb.OleDbConnection(Conn)
Dim SQL As String = "INSERT INTO People ([Name], [LastName])
VALUES(@Name, @LastName)" 'The @ Are Parameters
Dim tCommand As New OleDb.OleDbCommand(SQL, tConnection)

With tCommand

'Add Parameter Values

.Parameters.Add("@Name", OleDb.OleDbType.VarChar)
.Parameters(0).Value = txtname.Text
.Parameters.Add("@LastName", OleDb.OleDbType.VarChar)
.Parameters(1).Value = txtlastname.Text

'Open Connection
.Connection.Open()

'Execute
.ExecuteNonQuery()

'Close Connection
.Connection.Close()

End With 'Done with Command


End Sub
 
C

Cor Ligthert [MVP]

Bonzol,

Not another forum this is the code you got from GhostInAk in this forum.

He was only not using your field names. He left something for you to do
yourself.

Why it is his code, because I see seldom using people tCommand as mnemonic
for a command, mostly it is cmd.

Cor
 
B

Bonzol

The code he gave me was for SQL, I seeked help on another forum and
someone helped me. Don't worry I am very greatful for GhostinAk for
helping me. But Someone else showed me how to do this


..
Cor said:
Bonzol,

Not another forum this is the code you got from GhostInAk in this forum.

He was only not using your field names. He left something for you to do
yourself.

Why it is his code, because I see seldom using people tCommand as mnemonic
for a command, mostly it is cmd.

Cor


Bonzol said:
ok, finally got it for anyone else who wants to know also.
Some guy on another forum helped. Cheers anyway

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click


Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Documents and Settings\Pig\Desktop\New Folder\TEST.mdb;User
Id=admin;Password=;"
Dim tConnection As New OleDb.OleDbConnection(Conn)
Dim SQL As String = "INSERT INTO People ([Name], [LastName])
VALUES(@Name, @LastName)" 'The @ Are Parameters
Dim tCommand As New OleDb.OleDbCommand(SQL, tConnection)

With tCommand

'Add Parameter Values

.Parameters.Add("@Name", OleDb.OleDbType.VarChar)
.Parameters(0).Value = txtname.Text
.Parameters.Add("@LastName", OleDb.OleDbType.VarChar)
.Parameters(1).Value = txtlastname.Text

'Open Connection
.Connection.Open()

'Execute
.ExecuteNonQuery()

'Close Connection
.Connection.Close()

End With 'Done with Command


End Sub
 
B

Bonzol

it probbably happend that way, cause I refernced something from his
code to someone else.
 

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

Top