Updating DataGrid

G

Gary

I have two grids on a form. Contacts and Notes. For
each contact there can be many notes.

When I click on a contact (which is bound to the contact
table) I want to fill the notes grid and I use the
following code:

Dim cmdstring As String = "Select [date], [time],
endtime, [desc], con_id from Notes where con_id = '" &
Label3.Text & "'"
Dim da As New SqlClient.SqlDataAdapter

Dim ds As New DataSet

Dim daNotes1 As New SqlClient.SqlDataAdapter
(cmdstring, Me.SqlConnection2)
daNotes1.Fill(ds, "Notes")

Me.DG_Notes.DataSource = daNotes1
Me.DG_Notes.DataMember = "Notes"



But when I run the code I get an "unhandled error" on the
daNotes1.Fill line.

I took the cmdstring and put it into SQL Enterprise
manager and ran the query. Data was returned. Why is
this not filling the grid?

Any help would be appreciated.

Thanks

Gary
 
G

Guest

Hi Gary

I would suspect whether Me.SqlConnection2 is established or not

Bin Song, MC

----- Gary wrote: ----

I have two grids on a form. Contacts and Notes. For
each contact there can be many notes

When I click on a contact (which is bound to the contact
table) I want to fill the notes grid and I use the
following code

Dim cmdstring As String = "Select [date], [time],
endtime, [desc], con_id from Notes where con_id = '" &
Label3.Text & "'
Dim da As New SqlClient.SqlDataAdapte

Dim ds As New DataSe

Dim daNotes1 As New SqlClient.SqlDataAdapte
(cmdstring, Me.SqlConnection2
daNotes1.Fill(ds, "Notes"

Me.DG_Notes.DataSource = daNotes
Me.DG_Notes.DataMember = "Notes



But when I run the code I get an "unhandled error" on the
daNotes1.Fill line

I took the cmdstring and put it into SQL Enterprise
manager and ran the query. Data was returned. Why is
this not filling the grid

Any help would be appreciated

Thank

Gar
 
G

Gary

Hi Bin,

I just verified the connection to SqlConnection2 and it
works. I did a "Test Connection" and everything is OK.

Thanks

Gary
 
G

Guest

Hi Gary

Did you hand-coded the SqlConnection or created by drag and drop? Are you creating a windows app or web app? And where is your SQL Server, local or on the network

Bin Song, MCP


----- Gary wrote: ----

Hi Bin

I just verified the connection to SqlConnection2 and it
works. I did a "Test Connection" and everything is OK

Thank

Gar

-----Original Message----
Hi Gary
I would suspect whether Me.SqlConnection2 is established or not
Bin Song, MC
----- Gary wrote: ----
I have two grids on a form. Contacts and Notes.
For
each contact there can be many notes
When I click on a contact (which is bound to the
contact
table) I want to fill the notes grid and I use the
following code
Dim cmdstring As String = "Select [date], [time],
endtime, [desc], con_id from Notes where con_id = '" &> Label3.Text & "'
Dim da As New SqlClient.SqlDataAdapte
Dim ds As New DataSe
Dim daNotes1 As New SqlClient.SqlDataAdapte
(cmdstring, Me.SqlConnection2
daNotes1.Fill(ds, "Notes"
Me.DG_Notes.DataSource = daNotes
Me.DG_Notes.DataMember = "Notes on the
daNotes1.Fill line
I took the cmdstring and put it into SQL Enterprise
manager and ran the query. Data was returned. Why is
this not filling the grid
Any help would be appreciated
Thank
Gar
 
G

Guest

Bin,

I did some more checking and the SqlConnection was
created by drag and drop. AFter playing around I found
that the database owner was not "sa" but "sa" was in the
connection string so I replaced it. Now it gets further
but stops on the following line:

Me.DG_Notes.DataSource = daNotes1

The error I now get is :complex databinding accepts as a
data source either an Ilist or IListSource.

What am I doing wrong?


Thanks,

Gary
-----Original Message-----
Hi Gary,

Did you hand-coded the SqlConnection or created by drag
and drop? Are you creating a windows app or web app? And
where is your SQL Server, local or on the network?
Bin Song, MCP


----- Gary wrote: -----

Hi Bin,

I just verified the connection to SqlConnection2 and it
works. I did a "Test Connection" and everything is OK.
Thanks

Gary


-----Original Message-----
Hi Gary,
established
or not. Notes.
For
each contact there can be many notes.
the
contact
table) I want to fill the notes grid and I use the
following code:
Dim cmdstring As String = "Select [date],
[time],
endtime, [desc], con_id from Notes where
con_id
= '" &> Label3.Text & "'"
Dim da As New SqlClient.SqlDataAdapter SqlClient.SqlDataAdapter
(cmdstring, Me.SqlConnection2)
daNotes1.Fill(ds, "Notes")
Me.DG_Notes.DataMember = "Notes"
an "unhandled error"
on the
daNotes1.Fill line. Enterprise
manager and ran the query. Data was
returned. Why
is
this not filling the grid?
.
 
T

Trygve Lorentzen

You cannot bind to a DataAdapter only descendants of Ilist or IListSource. A
DataSet/DataTable is what you want to set the DataSource to here:

Me.DG_Notes.DataSource = ds.NOTES;

Bin,

I did some more checking and the SqlConnection was
created by drag and drop. AFter playing around I found
that the database owner was not "sa" but "sa" was in the
connection string so I replaced it. Now it gets further
but stops on the following line:

Me.DG_Notes.DataSource = daNotes1

The error I now get is :complex databinding accepts as a
data source either an Ilist or IListSource.

What am I doing wrong?


Thanks,

Gary
-----Original Message-----
Hi Gary,

Did you hand-coded the SqlConnection or created by drag
and drop? Are you creating a windows app or web app? And
where is your SQL Server, local or on the network?
Bin Song, MCP


----- Gary wrote: -----

Hi Bin,

I just verified the connection to SqlConnection2 and it
works. I did a "Test Connection" and everything is OK.
Thanks

Gary


-----Original Message-----
Hi Gary,
I would suspect whether Me.SqlConnection2 is
established
or not.
Bin Song, MCP
----- Gary wrote: -----
I have two grids on a form. Contacts and
Notes.
For
each contact there can be many notes.
When I click on a contact (which is bound to
the
contact
table) I want to fill the notes grid and I use the
following code:
Dim cmdstring As String = "Select [date], [time],
endtime, [desc], con_id from Notes where
con_id
= '" &> Label3.Text & "'"
Dim da As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim daNotes1 As New SqlClient.SqlDataAdapter
(cmdstring, Me.SqlConnection2)
daNotes1.Fill(ds, "Notes")
Me.DG_Notes.DataSource = daNotes1
Me.DG_Notes.DataMember = "Notes"
But when I run the code I get
an "unhandled error"
on the
daNotes1.Fill line.
I took the cmdstring and put it into SQL Enterprise
manager and ran the query. Data was
returned. Why
is
this not filling the grid?
Any help would be appreciated.
Thanks
Gary
.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top