Link to home
Start Free TrialLog in
Avatar of clebo99
clebo99

asked on

Simple DataGridView Question - Passing Variables

I'm a semi competent VB6 programmer trying to understand .Net 2005.  This is what I am trying to do:

- I have a form that has information in a datagridview that is a very simple SELECT statement for a very simple DB.
- I have configured the form so if I click on the cell, the value is placed into a public variable configured in a module.
- I want to use that variable in the WHERE statement in another Datagridview on a different form.

From what I am understanding, using datagridview limits you to direct SQL.  In the past in VB6, I would create my ADODB connections in the code.  Open the DB using a Function, create a string using the & to add my variable after the WHERE like below:

 str = "SELECT * from Approved WHERE PatchNum = '" & varname & "'"

So, how do I do this?  In the past, Ive used LISTVIEWs in VB6 and have been easily retrieved data in DBs.  I just cannot believe that doing the simple DB manipulations in VB6 are this complicated in .Net 2005.  

What am I missing?  Does my question make sense?  

Chris, Baltmore.
SOLUTION
Avatar of CooPzZ
CooPzZ
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clebo99
clebo99

ASKER

Thanks....this looks pretty good and I'll give this a try tonight.  A few quick followups:

- One thing I still don't see in the code is where what I selected in the first DataGrid is "appended" to the second select statement on the second form.  

So, my first "form" is going to give me 2 columns.  One with a  computer name and the second with a date of when the system was "added".  I click on the cell with the computer name and I can get that data (I have a MSGBOX that shows that I have grabbed this information correctly).  I then do a simple variablename = "selected cell" (I worked with the dateviewgrid "settings" to get that.  Took me about an hour to figure that out).  

Now, on the "Clicked Cell" action, I show the message box, I close the current form, then I open a second form.  This second form has a datagrid and I've easily been able to get data into that grid AND I've discovered that if I do something like "SELECT * FROM TABLE WHERE NAME = @variablename" in the dataview (I'm sorry I don't have .Net at work so I'm going by memory), a box on the top of the screen comes up and I can type in the system name there and the script works fine.  But, I want the @variablename to what I selected in that original cell that is shown in the MSG box.

- Again, in VB6, what I would do is just use a LISTVIEW and have a WHILE DO using the !variablename and placing that in the "columns" of the list box.  Quite frankly it was my bread and butter for writing applications connecting to DB's and I can still very quickly using that template make viable apps using VB6, but I'm trying to move ahead and do this with .Net 2005.    

Is it easier or a best practice to use a DataGridView or a LISTVIEW for these kinds of designs?  I would assume that a DataGridView would be the obvious choice, but if I am "limited" to only commands in genuine SQL and cannot pass a variable from a form into this statement, it's not much help (I would think this would be an issue for a lot of other programmers as well).

Again, thanks for the code.  Please comment if you think I am off base or even to validate that I'm kind of getting the jist of this.

Chris, Baltimore.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clebo99

ASKER

I know....long post by me.....actually I was able to do what I wanted to do using LISTVIEWS, which is what I am more comfortable with anyway using datareaders (my next step is to try datawriters, where I'll probably post a lot about for help).

I'm starting to like .Net more and more (seems like there is a lot more variable definitions required and this datareader/writer is really a big change from Recordsets).  

Thanks again for your help everyone.

chris