473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How i can select table1 and insert into table2?

Hello NG

i use Microsoft SQL server
and my problem is how i can select table1 into the dataset and insert this
datas into table2 (backup table).

Has someone a idea or a code example?

Thanks

Michael
Nov 15 '05 #1
4 2364
Michael,

It would be easy if you could change the RowState property on the
DataRow, so that you could simulate the adding of the rows by flipping the
flag for the state. However, this is not the case.

You can duplicate the structure of table 1, and then cycle through all
of the rows in table 1, adding them to table 2. Then, you can create a data
adapter for table 2 and then call the Update method on it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Michael" <NO**********************@naviti.ch> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hello NG

i use Microsoft SQL server
and my problem is how i can select table1 into the dataset and insert this
datas into table2 (backup table).

Has someone a idea or a code example?

Thanks

Michael

Nov 15 '05 #2
Hello Nicholas an thank you for your answer.

I'm not sure:

I have a select statement for tblFiBuErfassen

and now i can copy this dataadapter.....
Here i have a example is that the correct way?
---------------------------------------------------

private void FiBuBuchungBuchen()
{
MessageBox.Show("I'm here...");
// new dataadapter
da2 = new SqlDataAdapter();

SqlCommand cmdInsert= sqlCN.CreateCommand();
cmdInsert.CommandType = CommandType.Text;
cmdInsert.CommandText = "INSERT INTO tblFiBuBuchung " +
"(FiBuBuchungBuchungsnummer,
FiBuBuchungBuchungsdatum,FiBuBuchungBuchungstypID, "+
"FiBuBuchungKontenplanID, FiBuBuchungMWSTID, FiBuBuchungBelegnummer,
FiBuBuchungBuchungstext, "+
"FiBuBuchungBetragSoll, FiBuBuchungBetragHaben, FiBuBuchungName,
FiBuBuchungMandantID,FiBuBuchungUserID) " +
"VALUES(@FiBuBuchungBuchungsnummer,
@FiBuBuchungBuchungsdatum,@FiBuBuchungBuchungstypI D,"+

"@FiBuBuchungKontenplanID,@FiBuBuchungMWSTID,@FiBu BuchungBelegnummer,@FiBuBu
chungBuchungstext,"+
"@FiBuBuchungBetragSoll,@FiBuBuchungBetragHabe n, @FiBuBuchungName,
@FiBuBuchungMandantID,@FiBuBuchungUserID)";
cmdInsert.Parameters.Add("@FiBuBuchungID", SqlDbType.BigInt, 8,
"FiBuBuchungID");
cmdInsert.Parameters.Add("@FiBuBuchungBuchungsnumm er", SqlDbType.Int, 4,
"FiBuBuchungBuchungsnummer");
cmdInsert.Parameters.Add("@FiBuBuchungBuchungsdatu m",
SqlDbType.SmallDateTime, 4, "FiBuBuchungBuchungsdatum");
cmdInsert.Parameters.Add("@FiBuBuchungBuchungstypI D", SqlDbType.Int, 4,
"FiBuBuchungBuchungstypID");
cmdInsert.Parameters.Add("@FiBuBuchungKontenplanID ", SqlDbType.Int, 4,
"FiBuBuchungKontenplanID");
cmdInsert.Parameters.Add("@FiBuBuchungMWSTID", SqlDbType.Int, 4,
"FiBuBuchungMWSTID");
cmdInsert.Parameters.Add("@FiBuBuchungBelegnummer" , SqlDbType.NVarChar,
12, "FiBuBuchungBelegnummer");
cmdInsert.Parameters.Add("@FiBuBuchungBuchungstext ", SqlDbType.NVarChar,
50, "FiBuBuchungBuchungstext");
cmdInsert.Parameters.Add("@FiBuBuchungBetragSoll", SqlDbType.Float, 8,
"FiBuBuchungBetragSoll");
cmdInsert.Parameters.Add("@FiBuBuchungBetragHaben" , SqlDbType.Float, 8,
"FiBuBuchungBetragHaben");
cmdInsert.Parameters.Add("@FiBuBuchungName", SqlDbType.NVarChar, 30,
"FiBuBuchungName");
cmdInsert.Parameters.Add("@FiBuBuchungMandantID", SqlDbType.Int, 4,
"FiBuBuchungMandantID");
cmdInsert.Parameters.Add("@FiBuBuchungUserID", SqlDbType.Int, 4,
"FiBuBuchungUserID");

cmdInsert.Parameters["@FiBuBuchungID"].SourceVersion =
DataRowVersion.Original;

da.InsertCommand = cmdInsert;
try
{
da2.Update(ds,"tblFiBuBuchung");
}
catch (SqlException sqlExcp)
{
//Bei fehlerhaftem Zugriff wird Fehlermeldung ausgelöst
MessageBox.Show(this, sqlExcp.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}


Nov 15 '05 #3
Hm,

From where does he know that he must insert everything?

possibly I still changed the data befor in datagrid, of course i save
this data before I would like to write the data into the other table.

I tried the above example. Unfortunately does not go. I always get an
error message with the update

Thanks

Michael
Nov 15 '05 #4
Michael wrote:
Hello NG

i use Microsoft SQL server
and my problem is how i can select table1 into the dataset and insert this
datas into table2 (backup table).

Has someone a idea or a code example?


insert into table2 select * from table1

Make sure that table1 and table2 have the same structure.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Stadler | last post by:
Can someone help with query syntax regarding IN/EXISTS.. I'm trying to do this: insert into table2 (field1) select field1 from table1 where field1 not in (select field1 from table2) delete...
3
by: Jay K | last post by:
Hi, I have multiple queries like this: SELECT col1, col2, col3, col4 FROM table1, table2 where table1.col1 = table2.col1 and table1.col2 = 1 ORDER BY col3 desc LIMIT 5 and
2
by: Eric | last post by:
please help to select these rows from these tables my tables are table1 table1Id groupId table2id price 1 1 1 10 2 1 3 1000 3 1 ...
6
by: DC Gringo | last post by:
I have a series of select queries that use the nesting method but are creating such a huge query that the server can't handle it. The IN section in some cases are so large that I can't even...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
3
by: Alex | last post by:
Hi, I need to form a query where i can add some columns based on the result. Table A ColA, ColB ---------- 1 A 2 B
14
by: Yas | last post by:
Hello, I have 2 tables, Table1 and Table2. I have copied all data from Table1 to Table2. However Table1 is dynamic it has new rows added and some old rows modified everyday or every other...
10
by: Jeff Kish | last post by:
Can anyone tell me how to do this in sql server? I am currently doing this query in oracle: select table1.col1,table1.col2,table2.col3,table4.col4 where table1.col1 = table2.col3 and...
3
by: Brian | last post by:
I've tried for hours... and my issue is this: Table 1 has FirstName, LastName, Address, Birthday, (and other columns) Table 2 has FirstName, LastName, Address, Birthday, (and other columns) ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.