Problems accessing data from a SQL Server in VB.NET

bripoin

New member
Joined
May 24, 2006
Messages
4
Programming Experience
Beginner
I am having trouble with accessing information stored in a database on a SQL server using VB.NET. I've got two datagrids, one for information that never changes regarless of how many records, and one for information that is different each time. I'm using a SQLDataAdapter for each Datagrid and whenever I enter the identifying information in the textbox and hit the button to run the script, I get the following error:

"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

I can post the code if that would help. I've googled this error and I've not been able to find anything that helps so far. Could someone please help me?
 
Okay...I've figured out why I was getting the error and correctec that. But now, my information that repeats shows up several times, and the non-repeating data doesn't show up at all. I've stepped through the program and once it gets to that DataAdapter it give the error that the variable must be declared.
 
bripoin said:
I can post the code if that would help.
Nah, not necessary, we prefer to stumble around in the dark making wild arse gueses. Besides, everyone uses the Microsoft.Windows.MindReader namespace don't they? :rolleyes: ;)

-tg
 
Acctually, I've gotten now where it is loading the first datagrid just find. What I'm wanting to do is have it fill the second dataadapter using the information in the first field of DataGrid1 as a Parameter then load that to the second datagrid. Here is the code I've got for doing that:

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.VarChar)
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

I set the DataKey Field of DataGrid1 to the first field. However, when I run the code I get the following error:

Syntax error converting the varchar value 'PruID' to a column of data type int.

This leads me to believe that it is grabbing the column heading and not the acctual information that was loaded into the datagrid for that column, as that is the first column heading.
 
Alright, I'm trying something different now. I'm using a Master and a Detail grid to show this information in two different datagrids. I'm using the same parameter of "@PermitNum" to select the information for the Master grid, but I don't know if it's acctually using this parameter. Mainly because the application "times out" before it can ever load anything. Here's 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