0

I am a relative newbie and trying to insert multiple rows (and data from textboxes) from one table into another and am stuck.

This SQL identifies the data to be inserted into the table

strsql = "SELECT '" & textbox1.text & "', '" & Textbox2.text & "', "
strsql = strsql & " a.TaskNum, a.StartDay, a.NumofDays FROM VETTimeLines as a"
strsql = strsql & " ORDER BY a.StartDay"

I started out along the lines of -> Insert into StudentProgram Values() code shown above, after 3 days of trying I now look forward to your advice.

Many thanks in anticipation Peter

2
  • Did you successfully establish a connection with your database? What is the primary key column? Do you have the current insert code? Also what DBMS (MS-Access, SQL Server, etc.)? Commented Jan 6, 2014 at 4:18
  • 1
    What you're doing is dangerous and will get your databases hacked, probably sooner rather than later. Read up on sql injection attacks and parameterized queries before doing anything else here. Commented Jan 6, 2014 at 4:21

1 Answer 1

0

Inserting data using C# can be performed in variety of ways such as using Entity Framework or using ADO.NET, as you have chosen to do in this case.

Using ADO.NET you either write the insert as you did or by using DataAdapter approach. DataAdapter is capable of creating the SQL code for you, amongst other things. For example see:SQL DataAdapter. It is a good idea to not build a SQL string as you did because of sql injection threat as @Joel Coehoorn indicates in his comment above.

One way to overcome this is by using Parameters as shown in the above link. If you decide to provide the SQL for insert yourself with parameters, here is a good example:StackOverFlow-Insert using ADO.

The idea behind all of the above code is to create a connection object, create a parameter object, create a command object, open the database connection, execute the command and close the connection.

Try one of the above approaches and let's know your specific issue if any arises.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.