Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > Winforms Data Access

Winforms Data Access VB.NET development for data access and back-end related areas

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-06-2009, 4:27 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2009
Posts: 4
Reputation: 0
shruti is on a distinguished programming path ahead
Unhappy The multi-part identifier "System.Data.DataRowView" could not be bound.

Can someone please help me with this error

I have combo boxes where i populate data.
From there I take the selected value and fetch rest of the data from table to display it in datagridview.

Thanks in advance

Code:
Imports System.Data
Imports System.Data.SqlClient

Public Class binsearch

    Private Sub btn_binsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_binsearch.Click
        Dim con As New SqlConnection("xxxx")
        con.Open()
        Dim cmd As New SqlCommand
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "select Cylnumber,date  from [dbo].[Voltaix_BINCYL_Location] where Binnumber=" & cb_bin.SelectedValue

        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        Dim dt As New DataTable()
        da.Fill(dt)
        Dim source As New BindingSource()
        source.DataSource = dt
        dgv_data.DataSource = source
        con.Close()

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        ' Connecting to the database
      
        Dim conn As New SqlConnection("xxxxxx")
        conn.Open()
        Dim cmd1 As New SqlCommand()
        Dim cmd2 As New SqlCommand()

        cmd1.Connection = conn
        cmd2.Connection = conn

        cmd1.CommandType = CommandType.Text
        cmd2.CommandType = CommandType.Text

        cmd1.CommandText = "Select  Binnumber from [dbo].[Voltaix_BINCYL_Location]"
        cmd2.CommandText = "Select  Cylnumber  from [dbo].[Voltaix_BINCYL_Location]"

        Dim da1 As New SqlDataAdapter
        Dim da2 As New SqlDataAdapter

        Dim dt1 As New DataTable
        Dim dt2 As New DataTable

        da1.SelectCommand = cmd1
        da2.SelectCommand = cmd2

        da1.Fill(dt1)
        da2.Fill(dt2)

        Dim source1 As New BindingSource()
        Dim source2 As New BindingSource()

        source1.DataSource = dt1
        source2.DataSource = dt2

        cb_bin.DataSource = source1
        cb_cyl.DataSource = source2

        cb_bin.DisplayMember = "Binnumber"
        cb_bin.ValueMember = "Binnumber"

        cb_cyl.DisplayMember = "Cylnumber"
        cb_cyl.ValueMember = "Cylnumber"
        'cb_cyl.SelectedIndex = 0
        'cb_bin.SelectedIndex = 0

        'conn.Close()


    End Sub

    Private Sub btn_cylsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cylsearch.Click
        Dim con3 As New SqlConnection("xxxxxx")
        con3.Open()
        Dim cmd3 As New SqlCommand
        cmd3.Connection = con3
        cmd3.CommandType = CommandType.Text
        'cmd3.CommandText = "select Binnumber,date  from [dbo].[Voltaix_BINCYL_Location] where Cylnumber=" & cb_cyl.SelectedValue
        cmd3.CommandText = "select Binnumber,date  from [dbo].[Voltaix_BINCYL_Location] where Cylnumber =" & cb_cyl.SelectedItem.ToString


        'cmd3.CommandText = "Select Convert(Int, ParseName(Cylnumber,2)), date from [dbo].[Voltaix_BINCYL_Location] where Binnumber=" & cb_bin.SelectedValue

        Dim da3 As New SqlDataAdapter
        da3.SelectCommand = cmd3
        Dim dt As New DataTable()
        da3.Fill(dt)
        Dim source As New BindingSource()
        source.DataSource = dt
        dgv_data.DataSource = source
        con3.Close()
    End Sub
End Class
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-06-2009, 5:53 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

I'd suggest taking 8 minutes out of your development time and watch this: How Do I: Filter Data on the Client?.

You'll end up writing a whopping 1 line of code to do the same thing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-06-2009, 7:22 PM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 5,309
Reputation: 415
jmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NET
Default

While Matt's advice is sound enough, filtering at the client is not always desirable. What if you have millions of records in total? In that case filtering at the clinet would be slow to load the data initially and slow to filter each time. Retrieving a subset of data from the database each time would be a better choice. Local filtering is certainly easier and potentially quicker for relatively small amounts of data though.

As for the original question, maybe you could point out to us where the exception is thrown, so we don't have to search the code to find the problem in the first place.
__________________
Essential: Multiple Forms
101 Samples: 2002 | 2003 | 2005Free Components: WFC | XPCC | ElementsEx | VBPP | ADO.NET/MySQL | VisualStyles | NPlot | SDFTutorials: Home & Learn | Start VB.NET | Learn VB.NETFavourites: MSDN | WinForms.NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-07-2009, 9:14 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2009
Posts: 4
Reputation: 0
shruti is on a distinguished programming path ahead
Default

This error occours near the da.fill()
When i run this query with hard coded values then it executes perfect in the SQL Server 2005.

If I change the query into :
cmd3.CommandText = "select Binnumber,date from [dbo].[Voltaix_BINCYL_Location] where Cylnumber =" & cb_cyl.SelectedValue

I get error:
Conversion failed when converting the varchar value 'fasf' to data type int.

If I change the query into:
cmd3.CommandText = "select Binnumber,date from [dbo].[Voltaix_BINCYL_Location] where Cylnumber = '& cb_cyl.SelectedValue.ToString'"

I get only the headers of the columns and no data when actually there is one.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-07-2009, 9:18 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2009
Posts: 4
Reputation: 0
shruti is on a distinguished programming path ahead
Default

Specifically I am doing a test of the last part of my code.
So the exception is shown near the da3.fill(dt)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-07-2009, 10:02 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2009
Posts: 4
Reputation: 0
shruti is on a distinguished programming path ahead
Talking

Ok I got it
it was just a silly syntax error

huh

I replaced the query by :

cmd3.CommandText = "select Binnumber,date from [dbo].[Voltaix_BINCYL_Location] where Cylnumber='" & cb_cyl.SelectedValue & "'"


And it worked!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-07-2009, 10:14 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

Quote:
Originally Posted by jmcilhinney View Post
While Matt's advice is sound enough, filtering at the client is not always desirable. What if you have millions of records in total? In that case filtering at the clinet would be slow to load the data initially and slow to filter each time. Retrieving a subset of data from the database each time would be a better choice. Local filtering is certainly easier and potentially quicker for relatively small amounts of data though.

As for the original question, maybe you could point out to us where the exception is thrown, so we don't have to search the code to find the problem in the first place.
True.

I'll recommend cjard's thread on PQs for further reading shruti: The Ins and OUTs of Parameterized Queries... - Visual Basic .NET Forums
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-09-2009, 8:52 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,137
Reputation: 658
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Quote:
Originally Posted by jmcilhinney View Post
While Matt's advice is sound enough, filtering at the client is not always desirable. What if you have millions of records in total? In that case filtering at the clinet would be slow to load the data initially and slow to filter each time. Retrieving a subset of data from the database each time would be a better choice. Local filtering is certainly easier and potentially quicker for relatively small amounts of data though.
Though I'm sure that DW2 will containa valid lin kfor adding a filtering query to a tableadapter.. Check the Creating a Form to Search Data link
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:28 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.