473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Error when filling a datagrid.

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
Nov 22 '05 #1
1 1310
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
-----Original Message-----
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
.

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Angelina | last post by:
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...
1
by: dbuchanan | last post by:
VB.NET 2003 / SQLS2K The Stored Procedure returns records within Query Analyzer. But when the Stored Procedure is called by ADO.NET ~ it produced the following error message. ...
4
by: starwiz | last post by:
I'm trying to use the DataGrid's editing with a DropDownList. I've tried using every code sample I've seen and none of them seem to be able to solve my problem. When I call...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
6
by: vips | last post by:
Page_Load datagrid1.datasource=dataset1 //I am filling the datagrid and it works fine when page is displayed end ---------------
2
by: david | last post by:
Problem: There is a search button, Search, in form, for searching patient info list. The error occurs after the following steps: 1. search first time is OK, and all found the records are...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
1
by: WayneM | last post by:
I have compact framework app that I was trying to test out on a windows form, but I cannot get past the very first step of simply filling a DataGrid from a DataSet. My code is Dim sqlStmt As...
10
by: Roger | last post by:
ms-access97 & sql server2005 two tables tblItem tblItemFeature form frmItem contains subform frmItemFeature each form is based on their respective table creating new record and filling in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.