0

How can i add one record from a table to another table in vb.net?
Whats the instruction ?Using the instructions of squel , how can i put in the vb.net instructions?
ehsan2

5
Contributors
8
Replies
13
Views
13 Years
Discussion Span
Last Post by Reverend Jim
0

What database engine are you using? SQL Server? Microsoft Access? MySQL? Are you just using ADO.NET's DataTable?

0

What database engine are you using? SQL Server? Microsoft Access? MySQL? Are you just using ADO.NET's DataTable?

I am using SQL Server database.

0

What database engine are you using? SQL Server? Microsoft Access? MySQL? Are you just using ADO.NET's DataTable?

I AM USING SQL SERVER DATA BASE.

0

Syntax as such:
-with one statement

INSERT INTO table2 (column1, column2, ...)
SELECT column1, column2, ...
FROM table1
WHERE ...

Not sure if that is what you are asking for, or if you need the VB.NET pseudocode as well?

:cool:

0

INSERT INTO table2 (column1, column2, ...)
SELECT column1, column2, ...
FROM table1
WHERE ...
:cool:

I know this codes, but where and how i should write this code in vb.net? :cry:

Edited by Dani: Formatting fixed

0

Ok ehsan2, VB is just as easy as the SQL side. First, you can either write a Stored Procedure with this SQL code in SQL Server or you can hard code it in VB.Net. The latter is a more eligant way, but each to his own.

I assume you know how to connect to an SQL Database and Retrieve records with ADO.Net already (especially with the question you have asked being a moderate level task).

1. Create your Connection String
2. Create your Command Object
3. Create the SQL String (i.e. the Insert Select Statement) unless you are using a stored procedure
4. Pass sqlString and Connection object to Command
5. Open the Connection
7. ExecuteNonQuery Method of the Command Object and voila!

Example:

Dim myCommand As New SqlCommand(myExecuteQuery, myConnection)
    myCommand.Connection.Open()
    myCommand.ExecuteNonQuery()
    myConnection.Close()

Hope this helps!

-1

'Create the new row
Dim newRow as DataRow = myTable.NewRow

'Add some data to it
newRow("columnName1") = data1
newRow("columnName2") = data2

'Add it to the table
myTable.Rows.Add(newRow)

'Bind the table
treeList.DataSource = dt
treeList.DataBind

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.