using values in datagrid in stored procedure


Hello, I have a datagrid with 2 columns, 'Description' and 'Date'.  How do I retrieve the values from these 2 columns so I can use them as parameters in a  stored procedure that will add these rows from the datagrid into my database.

thanks
crussell96Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi crussell96;

To access the data in a data grid you can do the following.

Dim data As String  ' This should be of the same type as what is stored
                            ' in the data grid control

DataGridName.Item(RowIndex, ColumnIndex)

The value returned from this function is of type Object. You must cast it to its data type to be able to store it, in this case string.

data = DirectCast(DataGridName.Item(0, 0), String)

If you want the currently selected row you can do this.

data = DirectCast(DataGridName.Item(DataGridName.CurrentRowIndex, 0), String)

The row and column index are zero based.

I hope this was of some help.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crussell96Author Commented:
Ok, i understand what you are saying so far but what would I need to do to make this work with multiple rows in the datagrid.
Fernando SotoRetiredCommented:
I do not think that multiple selection is supported to return a collection of selected rows.
crussell96Author Commented:
Let me try and explain a little further exactly what I am doing.

I have a datagrid named dgClassStartDates with 2 colums displayed Description and date.  When the user clicks the 'Save' button it executes a stored procedure that accepts 3 parameters. 2 come from the datagrid and the third is a variable. The code for attaching and giving the values to the parameters is below.  Now I can get it to work fine with only 1 row in the datagrid but exactly what steps do I need to take if there are multiple rows in the datagrid.  


'Attach Parameters
cmdClassPeriodStartDatesAddNew.Parameters.Add(prmStartDescription)
cmdClassPeriodStartDatesAddNew.Parameters.Add(prmStartDate)
cmdClassPeriodStartDatesAddNew.Parameters.Add(prmCaseID)

'Give Parameters values
prmStartDescription.Value = frmCaseKeyDatesOpen.dgClassStartDates.Item(0, 0)        
prmStartDate.Value = frmCaseKeyDatesOpen.dgClassStartDates.Item(0, 1)
prmCaseID.Value = globalCaseID 'This is a variable

'Execute command
cmdClassPeriodStartDatesAddNew.ExecuteNonQuery()
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.