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

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

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.

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.

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:

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:

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!

'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 thread is more than nine years old and does not require a response. Please do not resurrect old threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.