More help needed with accessing data from a database

bripoin

Active member
Joined
Apr 26, 2006
Messages
25
Okay...Ive modified my original code so that I now have two datagrids. One is for the information that I am pulling from the database that is constant for every instance of information. The other is for information that varies from instance to instance. Ive gotten the first database to where it is pulling the correct information and I wrote the code so that it filters the info for the second datagrid by using the "PruID" pulled into the first datagrid. However, when I run the code, I get a blank datagrid for the second one. Here is the code for the click event:

Try
Me.SqlSelectCommand1.Parameters.Add("@PermitNum", SqlDbType.VarChar)
Me.SqlSelectCommand1.Parameters("@PermitNum").Value = TextBox1.Text
Me.LoadDataSet31()
Me.DataGrid1.SelectedIndex = -1
Me.DataGrid1.DataBind()
Me.SqlSelectCommand2.Parameters.Add("@PruID", SqlDbType.Variant)
Me.SqlSelectCommand2.Parameters("@PruID").Value = Me.DataGrid1.DataKeyField
Me.LoadDataSet51()
Me.DataGrid2.SelectedIndex = -1
Me.DataGrid2.DataBind()
Catch eLoad As System.Exception
Me.Response.Write(eLoad.Message)
End Try

Any ideas as to why this is happening?
 
Assuming that the select command are bound to the correct datasets, and the datasets to the correct grids...

Make sure Me.DataGrid1.DataKeyField is returning the right value

Me.SqlSelectCommand2.Parameters.Add("@PruID", SqlDbType.Variant)

set the PruID var to the correct type
 
I tried Text and got:
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

I tried VarChar and got:
Syntax error converting the varchar value PruID to a column of data type int.

I tried Int and got:
Input string was not in a correct format.

Those last two results lead me to believe that its grabbing the column heading with in the DataGrid instead of the information that was pulled from the database.
 
Debug it, what is the value of Me.DataGrid1.DataKeyField

Change

Me.SqlSelectCommand2.Parameters("@PruID").Value = Me.DataGrid1.DataKeyField

to

Me.SqlSelectCommand2.Parameters("@PruID").Value = int.Parse(Me.DataGrid1.DataKeyField)
 
When I try that I get "Overload resolution failed becasue no accessible "Int" accepts this number of arguments." The valule of the DataKeyField is a String that is pulled from the database with the first SQL Select command.
 
Alright, Im trying something different now. Im using a Master and a Detail grid to show this information in two different datagrids. Im using the same parameter of "@PermitNum" to select the information for the Master grid, but I dont know if its acctually using this parameter. Mainly because the application "times out" before it can ever load anything. Heres the code:

SqlSelectCommand1

Me.SqlSelectCommand1.CommandText = "SELECT tblPRUMaster.PruID, tblPRUMaster.PruNumber, tblPRUMaster.PruName, tblPRUMa" & _
"ster.NorthOrSouth, tblPRUMaster.PermitNo FROM tblPRUMaster INNER JOIN tblPRUProd" & _
"uction ON tblPRUMaster.PruID = tblPRUProduction.PruID WHERE (tblPRUMaster.PermitNo = @PermitNum)"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1

The code for the Button click:

Try
Me.SqlSelectCommand1.Parameters.Add("@PermitNum", SqlDbType.VarChar)
Me.SqlSelectCommand1.Parameters("@PermitNum").Value = TextBox1.Text
Me.LoadDataSet()
Me.masterDataGrid.SelectedIndex = -1
Me.masterDataGrid().DataBind()
Catch eLoad As System.Exception
Me.Response.Write(eLoad.Message)
End Try
 
Back
Top