hi,
I am working on an asp application using c# and i can import excel file to sql table
i have two columns in excel and as well as in sql of same name "id" and "status"
when i import data both columns are imported to sql table in the same sequence

is there in any way that i can match the id of both tables and where id are same i'll extract status from excel table and insert into sql table?

Recommended Answers

All 4 Replies

Okay so let me make sure I understand this right

First of all, have you successfully written the Excel file to an SQL Table?

Secondly, if an item has a same ID from the Excel file, then you extract it's status and add it to the SQL table.

If I am understanding you correctly, what you simply need to do is take the data out of the Excel file, store it in a 2D array (or List), and do some comparisons in there, with copying data to a new 2D array (or List) if it meets a criteria. Then finally, write that second 2D arrray (or List) to the SQL Table

angel yes u r quite right
let me explain it more
i have copied both columns from excel file to a tbl_temp sql table now i have IDs already present in my working(original) table what i want to do is to match the id from temp table to original table and put the status from tbl_temp to tbl_original
more specificaly
if id of tbl_temp = id of tbl_original
then status of tbl_temp = status of tbl_original
i have found this query
INSERT INTO tbl_original status SELECT ID FROM tbl_temp WHERE <condition>;
bt what should b the condition?

Okay so I think I see where you are coming from now, and let's look at that SQL statement you posted (FYI my knowledge of SQL comes from SQLite, which uses the same statements).

When I was working with SQLite, I started to build a list of functions in a class, that I could then reuse the class anytime I used SQLite. Well one of the functions was used to edit values. So I tweaked my statement a little to hopefully support your needs.,

UPDATE tbl_temp SET STATUS='place status here' WHERE ID='place ID here'

What this says is, in table tbl_temp, when every you see this ID (where I put "place ID here"), replace its status value with the specified status (where I put "place status here").

Does this help at all? All this does is update your data. I hope this is what you are looking for and I am not misreading it still (facepalm for me if I am)

This article is in C# and Vb.net and its simple. It uses SQLBulkCopy class.

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.