4 Replies - 1179 Views - Last Post: 09 October 2012 - 04:33 AM Rate Topic: -----

#1 Schweppes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

SQL Statement/Access/VBNet problem

Posted 03 October 2012 - 05:50 AM

Hey, first post here, sorry it's probably such a dumb one.

I'm creating a program in which the user enters data into a form (through text boxes), and hat data is then saved into a Access database.

I've used the Database wizard to connect the database and my VBNet program, but SQL statements are asking to be declared, so I must have missed some vital code out. All of the tutorials I've found assume you've already connected them properly.

I've got no code that relates to the actual connection between the database and the program, so I have nothing relevant to copy. Most of my code is just to do with the interaction between forums, and some validity checks.


Any help would be appreciated, if you need extra info just ask
Cheers. :)

Sorry about some of my spelling, forum is supposed to be form, etc. You can make out most of what I'm saying though.

Apparently I'm not allowed to edit yet. :( http://www.dreaminco...-to-edit-times/

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Statement/Access/VBNet problem

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1532
  • View blog
  • Posts: 4,908
  • Joined: 25-September 09

Re: SQL Statement/Access/VBNet problem

Posted 03 October 2012 - 07:02 AM

So on the form designer, does it have the objects for Dataset, BindingSource, TableAdapter and such...?

If so, the dataset should have the statements needed to perform various actions.

You can check this by right-clicking on the dataset and selecting Edit In DataSet Designer
Then when the Dataset opens, hilight FillData and select configure. Advanced should have an option for Generate INSERT, UPDATE and DELETE statements.
Was This Post Helpful? 0
  • +
  • -

#3 Schweppes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

Re: SQL Statement/Access/VBNet problem

Posted 09 October 2012 - 04:00 AM

View PostCharlieMay, on 03 October 2012 - 07:02 AM, said:

So on the form designer, does it have the objects for Dataset, BindingSource, TableAdapter and such...?

If so, the dataset should have the statements needed to perform various actions.

You can check this by right-clicking on the dataset and selecting Edit In DataSet Designer
Then when the Dataset opens, hilight FillData and select configure. Advanced should have an option for Generate INSERT, UPDATE and DELETE statements.


Thanks for the help, I managed to find where I should be inserting my SQL statements, as I was writing them in the wrong place prior.

Is there any special code I need to use to specify that the information from the relevant textboxes should be inserted into the Access database? This is my first time using SQL, so I'm pretty hopeless at it.

I'm thinking about

INSERT into tblStudentBasic(FirstName, Surname) VALUES (txtFirstName, txtSurname) 


But wouldn't that literally insert "txtFirstName" into the database rather than the actual data contained in the txtFirstName textbox?

If you need me to explain more clearly, please ask. Again, I'm using SQL to simply insert information from a textbox on a form into an Access Database.
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • Das kann nicht sein
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,637
  • Joined: 24-July 11

Re: SQL Statement/Access/VBNet problem

Posted 09 October 2012 - 04:06 AM

Have you tried that code yet? Isn't that a command string…? (Not too sure with databases)
If it is, then I'd do this:
"INSERT INTO tblStudentBasic(FirstName, Surname) VALUES (" & txtFirstName.Text & "," & txtSurname.Text & ")"


Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1532
  • View blog
  • Posts: 4,908
  • Joined: 25-September 09

Re: SQL Statement/Access/VBNet problem

Posted 09 October 2012 - 04:33 AM

View PostSchweppes, on 09 October 2012 - 07:00 AM, said:

I'm thinking about

INSERT into tblStudentBasic(FirstName, Surname) VALUES (txtFirstName, txtSurname) 


But wouldn't that literally insert "txtFirstName" into the database rather than the actual data contained in the txtFirstName textbox?

Yes and No, for a few reasons. No, because of the syntax errors that exist, but if you were to wrap txtFirstName with ' then yes it would.

What you will want to do is put placeholders (aka parameters) in place of your values and then set the textboxes as the values for the parameters.

In the objects an Sql Statement with parameters typically looks like:
INSERT into tblStudentBasic(FirstName, SurName) Values (?,?)
You would then define two parameters and set there values to txtFirstName and txtSurName
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1