Error when filling a datagrid.

  • Thread starter Thread starter Angelina
  • Start date Start date
A

Angelina

Hi,

Im in need of your help once again. I am truing to run a
stored procudure to fill a datagrid. However i keep
encountering the following error:

An unhandled exception of
type 'System.Data.SqlClient.SqlException' occurred in
system.data.dll

Additional information: System error.

the code stope on this line:
da.Fill(ds, "CaraEquip")


here is my full code. can anyone please tell me what im
doin wrong?


Private Sub RBtnEquipYes_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RBtnEquipYes.CheckedChanged

Dim Cn As New SqlConnection("data
source=PARAGLAPTOP\VSdotNET;initial
catalog=CaravanDBLapSQLServ;integrated
security=SSPI;persist security info=False;workstation
id=PARAGLAPTOP;packet size=4096")
Dim cmdCaraEquip As New SqlCommand("SPSelCaraEquip", Cn)
cmdCaraEquip.CommandType =
CommandType.StoredProcedure

cmdCaraEquip.Parameters.Add("@CaraName",SqlDbType.Char, 50)

cmdCaraEquip.Parameters("@CaraName").Value =
CBoxDisCaraNames.SelectedItem

da = New SqlDataAdapter("SPSelCaraEquip", Cn)

ds = New DataSet("CaraEquip")
da.Fill(ds, "CaraEquip")

DataGridEquip.DataSource = ds.Tables(0)

Dim TSCaraEquip As New DataGridTableStyle()
TSCaraEquip.MappingName = "CaraEquip"

Dim TCEquipName As New DataGridTextBoxColumn()
TCEquipName.MappingName = "Equip_Name"
TCEquipName.HeaderText = "Equipment Name"
TCEquipName.Width = 150
TCEquipName.ReadOnly = True
TSCaraEquip.GridColumnStyles.Add(TCEquipName)

DataGridEquip.TableStyles.Add(TSCaraEquip)

DataGridEquip.CaptionText = "Select the meals you wish to
book:"

If RBtnEquipYes.Checked = True Then DataGridEquip.Visible
= True


thx
 
The code appears to set the paramaters for the stored
procedure in the command object and then you pass the name
of the sp to the da. The da has no knowledge of the cmd
object. I think that is your problem.

First, I would put a try catch around the code so that you
don't get an unhandled exception.

Try
... your code
Catch ex as System.Exception
MsgBox(ex.ToString)
End Try

The msgbox will tell you exactly what problem you are
geting.

Hope this helps.

Articles, books, free code, add-ins, general .NET help at
http://www.knowdotnet.com
 
Back
Top