Problems with datasource for a grid control / sqldataadapter / dataset. 
Author Message
 Problems with datasource for a grid control / sqldataadapter / dataset.

Hello all,

I'm having some problems with one of my forms.

I have a listbox (lbxcust) which is populated via a stored proecure /
datareader on form load (Form code below)

In the index changed event of the listbox, I'm using the value from the
listbox as an argument to another sql stored procedure that I'm looking at
using to populate a dataset.
The dataset is intended to be the datasource for a listbox (gridquote).

Things work fine the first time I click on the listbox, but the second time
round, I get the message:

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

Additional information: System error. ####

This is happening on the       sda.Fill(ds, "quotes")   line within the
index changed event of lbxcust.

Am I doing something fundamentally wrong here??????

Many Thanks,

John.

===================================================

Public Class frm_recall_quote

Inherits System.Windows.Forms.Form

Private sqlcon As New SqlConnection(constring)

Private quotesqlcom As New SqlCommand("get_quotes")

Private sda As New SqlDataAdapter(quotesqlcom)

Private ds As New DataSet()

Private Sub lbxCust_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lbxCust.SelectedIndexChanged

Dim mystring As String

Dim myinteger As Int32

Dim myarg As String

mystring = lbxCust.Text

myinteger = mystring.IndexOf(" ")

myarg = Microsoft.VisualBasic.Left(lbxCust.Text, myinteger)

If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

quotesqlcom.CommandType = CommandType.StoredProcedure

quotesqlcom.CommandText = "get_quote"


quotesqlcom.Connection = sqlcon

sda.Fill(ds, "quotes")

End Sub

Private Sub frm_recall_quote_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Open our sql connection

If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

' Lets populate our listbox

lbxCust.Items.Clear() ' Clear it first to avoid duplication

Dim reader As SqlDataReader

Dim sqlcom As New SqlCommand()

sqlcom.Connection = sqlcon

sqlcom.CommandType = CommandType.StoredProcedure

sqlcom.CommandText = "get_all_customers"

reader = sqlcom.ExecuteReader

With reader

While reader.Read = True

lbxCust.Items.Add(UCase(reader(0)) & " " & reader(1))

End While

End With

reader.Close()

End Sub

End Class

===================================================

--
JC
Funky Business
http://www.*-*-*.com/



Sun, 31 Jul 2005 23:00:40 GMT  
 Problems with datasource for a grid control / sqldataadapter / dataset.
can you put the full call for the param of your stored
proc and if you clean your table put the code to I want to
try but the error msg isn't so significant.If you can make
a try catch to intersep the full exception call to.
Try

Quote:
>-----Original Message-----

>Hello all,

>I'm having some problems with one of my forms.

>I have a listbox (lbxcust) which is populated via a
stored proecure /
>datareader on form load (Form code below)

>In the index changed event of the listbox, I'm using the
value from the
>listbox as an argument to another sql stored procedure
that I'm looking at
>using to populate a dataset.
>The dataset is intended to be the datasource for a

listbox (gridquote).
Quote:

>Things work fine the first time I click on the listbox,
but the second time
>round, I get the message:

>#### An unhandled exception of

type 'System.Data.SqlClient.SqlException'

- Show quoted text -

Quote:
>occurred in system.data.dll

>Additional information: System error. ####

>This is happening on the       sda.Fill(ds, "quotes")  
line within the
>index changed event of lbxcust.

>Am I doing something fundamentally wrong here??????

>Many Thanks,

>John.

>===================================================

>Public Class frm_recall_quote

>Inherits System.Windows.Forms.Form

>Private sqlcon As New SqlConnection(constring)

>Private quotesqlcom As New SqlCommand("get_quotes")

>Private sda As New SqlDataAdapter(quotesqlcom)

>Private ds As New DataSet()

>Private Sub lbxCust_SelectedIndexChanged(ByVal sender As
System.Object,
>ByVal e As System.EventArgs) Handles

lbxCust.SelectedIndexChanged

- Show quoted text -

Quote:

>Dim mystring As String

>Dim myinteger As Int32

>Dim myarg As String

>mystring = lbxCust.Text

>myinteger = mystring.IndexOf(" ")

>myarg = Microsoft.VisualBasic.Left(lbxCust.Text,
myinteger)

>If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

>quotesqlcom.CommandType = CommandType.StoredProcedure

>quotesqlcom.CommandText = "get_quote"


>quotesqlcom.Connection = sqlcon

>sda.Fill(ds, "quotes")

>End Sub

>Private Sub frm_recall_quote_Load(ByVal sender As

System.Object, ByVal e As

- Show quoted text -

Quote:
>System.EventArgs) Handles MyBase.Load

>' Open our sql connection

>If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

>' Lets populate our listbox

>lbxCust.Items.Clear() ' Clear it first to avoid
duplication

>Dim reader As SqlDataReader

>Dim sqlcom As New SqlCommand()

>sqlcom.Connection = sqlcon

>sqlcom.CommandType = CommandType.StoredProcedure

>sqlcom.CommandText = "get_all_customers"

>reader = sqlcom.ExecuteReader

>With reader

>While reader.Read = True

>lbxCust.Items.Add(UCase(reader(0)) & " " & reader(1))

>End While

>End With

>reader.Close()

>End Sub

>End Class

>===================================================

>--
>JC
>Funky Business
>http://www.funky-business.co.uk

>.



Sun, 31 Jul 2005 23:55:07 GMT  
 Problems with datasource for a grid control / sqldataadapter / dataset.
Isn't this always the way - I moved the PRIVATE declarations from the top of
the form and put them into my index changed procedure and everything works!!

Could have sworn I'd tried that before posting...

Sorry for wasting your bandwidth folks !!!

JC


Quote:
> can you put the full call for the param of your stored
> proc and if you clean your table put the code to I want to
> try but the error msg isn't so significant.If you can make
> a try catch to intersep the full exception call to.
> Try

> >-----Original Message-----

> >Hello all,

> >I'm having some problems with one of my forms.

> >I have a listbox (lbxcust) which is populated via a
> stored proecure /
> >datareader on form load (Form code below)

> >In the index changed event of the listbox, I'm using the
> value from the
> >listbox as an argument to another sql stored procedure
> that I'm looking at
> >using to populate a dataset.
> >The dataset is intended to be the datasource for a
> listbox (gridquote).

> >Things work fine the first time I click on the listbox,
> but the second time
> >round, I get the message:

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

> >Additional information: System error. ####

> >This is happening on the       sda.Fill(ds, "quotes")
> line within the
> >index changed event of lbxcust.

> >Am I doing something fundamentally wrong here??????

> >Many Thanks,

> >John.

> >===================================================

> >Public Class frm_recall_quote

> >Inherits System.Windows.Forms.Form

> >Private sqlcon As New SqlConnection(constring)

> >Private quotesqlcom As New SqlCommand("get_quotes")

> >Private sda As New SqlDataAdapter(quotesqlcom)

> >Private ds As New DataSet()

> >Private Sub lbxCust_SelectedIndexChanged(ByVal sender As
> System.Object,
> >ByVal e As System.EventArgs) Handles
> lbxCust.SelectedIndexChanged

> >Dim mystring As String

> >Dim myinteger As Int32

> >Dim myarg As String

> >mystring = lbxCust.Text

> >myinteger = mystring.IndexOf(" ")

> >myarg = Microsoft.VisualBasic.Left(lbxCust.Text,
> myinteger)

> >If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

> >quotesqlcom.CommandType = CommandType.StoredProcedure

> >quotesqlcom.CommandText = "get_quote"


> >quotesqlcom.Connection = sqlcon

> >sda.Fill(ds, "quotes")

> >End Sub

> >Private Sub frm_recall_quote_Load(ByVal sender As
> System.Object, ByVal e As
> >System.EventArgs) Handles MyBase.Load

> >' Open our sql connection

> >If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

> >' Lets populate our listbox

> >lbxCust.Items.Clear() ' Clear it first to avoid
> duplication

> >Dim reader As SqlDataReader

> >Dim sqlcom As New SqlCommand()

> >sqlcom.Connection = sqlcon

> >sqlcom.CommandType = CommandType.StoredProcedure

> >sqlcom.CommandText = "get_all_customers"

> >reader = sqlcom.ExecuteReader

> >With reader

> >While reader.Read = True

> >lbxCust.Items.Add(UCase(reader(0)) & " " & reader(1))

> >End While

> >End With

> >reader.Close()

> >End Sub

> >End Class

> >===================================================

> >--
> >JC
> >Funky Business
> >http://www.funky-business.co.uk

> >.



Mon, 01 Aug 2005 00:05:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Grid update sqldataadapter dataset UpdateCommand Object Reference

2. What is difference between SqlDataAdapter and DataSet ?

3. controling transaction using dataset and sqldataadapter

4. Loading tables from a database via SQLDataAdapter and SQLDataAdapter.Fill

5. DataSource Property of Grid Controls

6. Offline dataset as a datagrid datasource

7. updating a datasource from a dataset

8. dataset problems - cant update sql after editing dataset

9. Problem binding a dataset to an user control property

10. User Control Text Box - Problems with DataSource

11. ADODC data control datasource problem

12. Dataset changes updates grid , How to update SQL table

 

 
Powered by phpBB® Forum Software