Insert Into

Joined
Aug 3, 2002
Messages
19
Hey All,

I know this is a really dumb question to ask but I just dont know how to accomplish this using ADO.net... so im asking for help...

Ive created a VB application and i need to insert data into an Access Database..

Ive read some tutes and they have a whole load of codes just to do an insert statement... can someone help me out with this...

i need to insert some data into a table called "PersonalDetails"

Heres a snippet of the code... but it doesnt work.. Please help

Comm.Connection = DatabaseCon
Comm.CommandText = "INSERT INTO PersonalDetails"
Comm.Parameters("PatientID").Value = PatientIDTxt.Text
Comm.ExecuteNonQuery()

Thank You
 
Youre inserting the data into a table? Not using a procedure or anything?

Dont use Parameters and just set the CommandText to something like this;
INSERT INTO PersonalDetails (PatientID) VALUES (234)
 
Hey wyrd... ok tried what youve told me to do but am facing this problem...

I get an error that says "Additional information:Prompt cannot be converted to type String"

this is what my code looks like

Comm.CommandText = "INSERT INTO PersonalDetails "_
& "(PatientID, Name) VALUES (123,Test)"
Comm.ExecuteQuery()

ok this doesnt seem to be working for me at this point... what idiotic thing have i done wrong?

Thank You
 
Hey Silv3rSurf3r_20 slow down, lean back and relax. ;)
You have to consider the datatype when inserting records into a table.
This was just a code sample of wyrd.
So; maybe Im wrong, but 123 in connection with PatientId does not sound like a string-value.
If Im right just leave the apostrophes, then it should work.
 
hey people... i dont know what the problem is wit this block of try and catch... i cant seem to insert anything into my database which is an Access Database

heres the code snippet
Try
DatabaseCon.Open()
Try
Comm.Connection = DatabaseCon
Comm.CommandText = "INSERT INTO PersonalDetails(PatientID, Name, Age) VALUES(234, test, 17)"
Comm.ExecuteNonQuery()
Finally
DatabaseCon.Close()
End Try
Catch ex As Exception
MsgBox(ex)
End Try

the error i get is...
Argument Prompt cannot be converted to type String

please advice... thank you
 
it seems the problem comes from the databasecon.open bit
my connection string looks pretty normal...
this is what it looks like
DatabaseCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Application.StartupPath & "\Database\DesaDentalDatabase.mdb"
its declared publically in a class module...

am i missing out something here... it used to work... now its gone strange on me...
 
ok got the connection to get working now...
my final question would be... how do i insert the values from a text box i.e. PatientIDTxt.Text
its not
VALUES (PatientIDTxt.Text) is it?
tried that... it doesnt work...
 
From your snippet of code there it looks like youre inserting it as regular text. You need to do string concatination to insert it using the Text properties value.
 
ok thank wyrd... it works now... got a question for you though... quite used to the idea of doing things in ado and then i migrated to ado.net is there another way you can insert values into the database... like the way ado did it... so it was easier to check where the error statement was coming from... because right nowi have a whole chunk of an insert into command... and when it kicks out i dont know where exactly the error was generated from... any tips on how i could get this done?
 
Back
Top