Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
 
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 13-Feb-13 23:09pm
ankur7891.4K
Edited 13-Feb-13 23:39pm
Maciej Los170.4K
v2
Comments
Maciej Los at 14-Feb-13 4:46am
   
Do you want to get all bills or the bill for the currently selected empid?
AnkurGupta OM at 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 at 14-Feb-13 12:21pm
   
Is your DataGridView placed on window form? How do you load data into this DataGridView (from where they comming)?
AnkurGupta OM at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not sure what you exactly want to do, because below query:
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:
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?
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150326.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100