Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Data Grid view Name as
DG1
The columns in this data grid are
Id, month, bill
and the values are


ID        MONTH            BILL
1            1              200
2            1              300
3            1              300
MORE VALUES ARE ALSO IN THIS VIEW

I WANT TO USE THE COMMAND AS

VB
cm=new SQLCommand(select * from Bill where empid in(values of id from data grid view ))

how can i write in statement for datagrid view
values of id from data grid view
Posted
Updated 13-Feb-13 22:39pm
v2
Comments
Maciej Los 14-Feb-13 4:46am    
Do you want to get all bills or the bill for the currently selected empid?
ankur789 14-Feb-13 5:40am    
sir i want to check in the database that is there any duplicate value in the database on the basis of datagrid view id field
Maciej Los 14-Feb-13 12:21pm    
Is your DataGridView placed on window form? How do you load data into this DataGridView (from where they comming)?
ankur789 14-Feb-13 22:51pm    
Yes Sir grid view is on the window form and i get the data in it by uploading an excel file in the grid view.
Richard MacCutchan 14-Feb-13 4:52am    
You would need to extract the gridview items by specifying row and column, and use them to create a set of values that can be used by the SQLCommand.

1 solution

I'm not sure what you exactly want to do, because below query:
SQL
select * from Bill where empid in(values of id from data grid view )

will fetch only records which are equal, but not duplicated. If this is your intension, try to use below query in MS SQL Server Management Studio to see result:
SQL
SELECT *
FROM (
    SELECT 'Excel' AS [Source], [ID], [MONTH], [BILL]
    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=E:\Example.xls', 'SELECT * FROM [Sheet1$]') 
    UNION ALL
    SELECT 'SQL Server' AS [Source], [ID], [MONTH], [BILL]
    FROM Bill)
ORDER BY  [ID], [MONTH], [Source]

An extra [Source] field is to identify the source of data.

Is that what you want do to in VB.NET code?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900