Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert excel sheet into sql server using vb 6?

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
LK
I have a excel sheet as below,
e1_piebmc.gif


And now I want to get these data into my sql server as below,
E2_m2sprl.gif


When inserting data into my sql server I don't want to insert duplicates and null records.
How can I do this?

Thank you.
 
Onc e again, your examples don't make sense - the output you show does not match your requirements. For example, what has happened to "2 mark in" or "96 mark dart"?
 
I don't want to take them because those records haven't all three columns.
 
In VB6, open your Excel file, point to your worksheet if needed.
Start in row 4 (Row counter)[pre]
If Columns E, F and H have values Then
If those values do NOT exist in your table Then
Insert this record to your table
End If
End If
Add 1 to your Row counter
If next row is Empty
You are done.
End If
[/pre]
Reset your Row counter to 4 (again) and
Repeat the same for Columns Q, R, and U

Actually, you do not even need VB6, you can use (pretty much) exactly the same code to do all of that from Excel’s VBA. To be honest, the code would be even shorter since you do not need to connect/point to Excel, you would already be in Excel
[wiggle]
---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
You know - first you do it the hard way, and then you improve it.
Better than the other way around... [thumbsup2]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Niki_S,
Any progress... [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top