Passing info to a SQL DB with a button

I know this is easy.. but i cant find anything im looking for

Page 1 of 1

1 Replies - 1024 Views - Last Post: 23 March 2007 - 08:08 AM Rate Topic: -----

#1 boniggy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-March 07

Passing info to a SQL DB with a button

Posted 22 March 2007 - 06:29 PM

Ok i have a VERY simple database im working on. It has 6 tables in it and one of the tables is where im putting the actual information i need to query for later on; that table is called "Distro Center". I have a form that i will have my users fill out (21 different fields) and hit the ADD button to add it into the SQL Express 2005 DB. Out of all 6 tables, 5 have information in them that are constant, meaning the forms pulls from those and displays them into dropdown boxes.

My simple request is how the flip do i make my ADD button add all the 21 fields into a new row in the database? I've written the query that i think it needs to make it work. When i execute the query it asks me to input data into the DB directly. All i want is the button to add it into the DB. I've looked for anytihng on this for the past 2-3hours and have found nothing that looks like it'll work. PLEASE HELP!

Im using VB 2005 with SQL Express 2005 on a seperate SQL DB Server.I've added the query that i made for it using the INSERT command. I just dont know how to code the button to dump what data has been filled out on the form to the DB... Does that make sense?



INSERT INTO [Distro Center]
					  ([DC Number], [DC Type], Address1, Address2, City, State, [Zip Code], [Phone Number], [Fax Number], [Contact 1], [Contact 2], [DC Alignment], 
					  [Hours of Operation 1], [Hours of Operation 2], ID, Email1, Email2, MiscInfo, [Hours of Operation 3], [Hours of Operation 4])
VALUES	 (@DC_Number,@DC_Type,@Address1,@Address2,@City,@State,@Zip_Code,@Phone_Number,@Fax_Number,@Contact_1,@Contact_2,@DC_Alignment,@Hours_of_Operation_1,@Hours_of_Operation_2,@ID,@Email1,@Email2,@MiscInfo,@Hours_of_Operation_3,@Hours_of_Operation_4); 
SELECT [DC Number], [DC Type], Address1, Address2, City, State, [Zip Code], [Phone Number], [Fax Number], [Contact 1], [Contact 2], [DC Alignment], [Hours of Operation 1], [Hours of Operation 2], ID, Email1, Email2, MiscInfo, [Hours of Operation 3], [Hours of Operation 4] FROM [Distro Center] WHERE (ID = @ID)



Advanced Thanks for anybody that can help!
-Jacob

Is This A Good Question/Topic? 0
  • +

Replies To: Passing info to a SQL DB with a button

#2 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Passing info to a SQL DB with a button

Posted 23 March 2007 - 08:08 AM

use a sqlcommand object and pass each of the values of the comboboxes/textboxes to the parameters of the stored procedure. change the command type to stored procedure and executenonreader on the sqlcommand object. this will execute the sqlcommand and give back either the number of rows affected (sucessful would be 1 in this case) or an error if the syntax is not correct.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1