DataSet Question...
DataSet Question...
DataSet Question...
DataSet Question...
DataSet Question...
DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question...
DataSet Question... DataSet Question...
DataSet Question...
Go Back  Xtreme Visual Basic Talk > > > DataSet Question...


Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2011, 01:45 PM
sanderson sanderson is offline
Junior Contributor
 
Join Date: Feb 2006
Location: Minnesota, USA
Posts: 217
Default DataSet Question...


Sorry if this is in the wrong forum. I've had absolutely no response th the posrs placed elsewhere.

All I want to do is coun t the coumns in my dataset. It's always 0!

Thanks for the help.

HTML Code:
    Private Function GetVantageData(ByVal index As Integer) As Array
        sql = "SELECT tblPart.PartNum, tblPart.PartDesc, tblPart.TypeCode, tblPart.UnitPrice, tblPartRev.RevisionNum, tblPartRev.Approved, tblPartBin.Onhandqty " & _
              "FROM SharePointProgress.dbo.tblPart " & _
              "LEFT OUTER JOIN SharePointProgress.dbo.tblPartRev ON tblPart.PartNum = tblPartRev.PartNum " & _
              "LEFT OUTER JOIN SharePointProgress.dbo.tblPartBin ON tblPart.PartNum = tblPartBin.PartNum " & _
              "WHERE tblPartRev.Approved = 1 " & _
              "AND tblPart.PartNum = '031770' "
        ' "AND tblPart.PartNum = '" & GetRoot(vb.Left(adoc(index), InStr(adoc(index), ".") + 7)) & "' "

        Dim cn_i As New SqlConnection(cn)
        cn_i.Open()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn_i)
        Dim ds As New DataSet
        da.Fill(ds)
        cn_i.Close()
        ' Create an array from the dataset.  There should be only one record to return
        Dim dt As New DataTable("Table 2")
        ds.Tables.Add(dt)

        Dim cnt As Integer = 0
        Dim dc As DataColumn
        For Each dc In dt.Columns
            cnt = cnt + 1 ' WHY IS THIS ZERO!!!

        Next

        MessageBox.Show(cnt)

        Dim abom2(cnt - 1) As String
        ReDim abom2(cnt - 1)
        For x As Integer = 0 To dt.Columns.Count - 1
            abom2(x) = dt.Rows(0)(x)
            MessageBox.Show(abom2(x))

        Next

        Return abom2

    End Function
Reply With Quote
  #2  
Old 11-03-2011, 02:48 PM
PlausiblyDamp's Avatar
PlausiblyDampDataSet Question... PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The line of code
Code:
  da.Fill(ds)
is creating a DataTable in the DataSet for you, when you then do
Code:
Dim dt As New DataTable("Table 2")
ds.Tables.Add(dt)
you are adding a second DataTable to the DataSet, the following code
Code:
For Each dc In dt.Columns
    cnt = cnt + 1 ' WHY IS THIS ZERO!!!
is using your second (and empty table) rather than the one the DataAdapter created and loaded.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 11-03-2011, 02:51 PM
sanderson sanderson is offline
Junior Contributor
 
Join Date: Feb 2006
Location: Minnesota, USA
Posts: 217
Default

How can I keep everything in and append to one DataTable? This may be the problem.

Thanks!
Reply With Quote
  #4  
Old 11-03-2011, 02:54 PM
PlausiblyDamp's Avatar
PlausiblyDampDataSet Question... PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The SqlDataAdapter has an overload of Fill that takes a DataTable as a parameter (http://msdn.microsoft.com/en-us/library/905keexk.aspx) - use that rather than passing in a DataSet
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 11-03-2011, 03:42 PM
sanderson sanderson is offline
Junior Contributor
 
Join Date: Feb 2006
Location: Minnesota, USA
Posts: 217
Default

Is this method valid if not all the data is from a database?

Basically I have two sources, one from an SQL quesy and one from a PDM databaseless vault that looks at BOMS through an API. I am using conventional Arrays to gerenate the information.

HTML Code:
Imports System
Imports System.Diagnostics
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.IO
Imports System.Math
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms

Imports ADODB

Imports vb = Microsoft.VisualBasic

Public Class Form2
    Dim cn As String = ("Data Source=SQL2;Initial Catalog=SharePointProgress;User Id=ProgressLink;Password=$s4SharePoint;")
    Dim sql As String

    Dim ECONum As String
    Dim ECRDate As Date
    Dim REQIDLast As String
    Dim REQIDInit As String
    Dim ENGID As String
    Dim SERIALNum As String
    Dim JOBNum As String

    Dim ds As New DataSet
    Dim dt As New DataTable(0)

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

    End Sub

    Private Sub LoadDataGridView(ByVal sql As String)
        Dim cn_i As New SqlConnection(cn)
        cn_i.Open()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn_i)
        da.Fill(ds)
        cn_i.Close()
        dgvFBOM.DataSource = ds.Tables(0)
        For c As Integer = 0 To dgvFBOM.Columns.Count - 1
            dgvFBOM.Columns(c).ReadOnly = True
            Select Case c
                Case 0
                    dgvFBOM.Columns(c).Width = 120

                Case 1
                    dgvFBOM.Columns(c).Width = 360

                Case 2
                    dgvFBOM.Columns(c).Width = 80

                Case 3
                    dgvFBOM.Columns(c).Width = 80

                Case 4
                    dgvFBOM.Columns(c).Width = 100

                Case 5
                    dgvFBOM.Columns(c).Width = 80

                Case 6
                    dgvFBOM.Columns(c).Width = 80

            End Select

        Next

        ' Row height is too slow...
        'For r As Integer = 0 To dgvVantageLookuptable.Rows.Count - 1
        '    dgvVantageLookuptable.Rows(r).Height = 16

        'Next

    End Sub

    Private Sub LoadDataGridViewM()
        ds.Tables.Add(dt)
        Dim dc0 As New DataColumn("PartNum")
        dt.Columns.Add(dc0)
        Dim dc1 As New DataColumn("PartDesc")
        dt.Columns.Add(dc1)
        Dim dc2 As New DataColumn("TypeCode")
        dt.Columns.Add(dc2)
        Dim dc3 As New DataColumn("UnitPrice")
        dt.Columns.Add(dc3)
        Dim dc4 As New DataColumn("RevisionNum")
        dt.Columns.Add(dc4)
        Dim dc5 As New DataColumn("Approved")
        dt.Columns.Add(dc5)
        Dim dc6 As New DataColumn("Onhandqty")
        dt.Columns.Add(dc6)
        Dim dc7 As New DataColumn("InABOM")
        dt.Columns.Add(dc7)

        Dim dr As DataRow

        For x As Integer = 0 To adoc.GetUpperBound(0)
            dr = ds.Tables(0).NewRow()
            Dim abom() As String = GetVantageData(x)

            dr.Item(0) = GetRoot(adoc(x))
            'dr.Item(1) = abom(0)
            'dr.Item(2) = abom(1)
            'dr.Item(3) = abom(2)
            'dr.Item(4) = abom(3)
            'dr.Item(5) = abom(4)
            'dr.Item(6) = abom(5)

            dt.Rows.Add(dr)

        Next

        dgvFBOM.DataSource = dt

    End Sub

    Private Function GetRoot(ByVal FileName As String) As String
        FileName = Trim(FileName)
        FileName = vb.Left(FileName, Len(FileName) - 7)
        If vb.Right(FileName, 1) = "." Then
            FileName = vb.Left(FileName, Len(FileName) - 1)

        End If
        Return FileName

    End Function

    Private Function GetVantageData(ByVal index As Integer) As Array
        sql = "SELECT tblPart.PartNum, tblPart.PartDesc, tblPart.TypeCode, tblPart.UnitPrice, tblPartRev.RevisionNum, tblPartRev.Approved, tblPartBin.Onhandqty " & _
              "FROM SharePointProgress.dbo.tblPart " & _
              "LEFT OUTER JOIN SharePointProgress.dbo.tblPartRev ON tblPart.PartNum = tblPartRev.PartNum " & _
              "LEFT OUTER JOIN SharePointProgress.dbo.tblPartBin ON tblPart.PartNum = tblPartBin.PartNum " & _
              "WHERE tblPartRev.Approved = 1 " & _
              "AND tblPart.PartNum = '031770' "
        ' "AND tblPart.PartNum = '" & GetRoot(vb.Left(adoc(index), InStr(adoc(index), ".") + 7)) & "' "

        Dim cn_i As New SqlConnection(cn)
        cn_i.Open()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn_i)
        da.Fill(ds)
        cn_i.Close()
        ds.Tables.Add(dt)

        Dim abom2(dt.Columns.Count - 1) As String
        ReDim abom2(dt.Columns.Count - 1)
        For x As Integer = 0 To dt.Columns.Count - 1
            abom2(x) = dt.Rows(0)(x)
            MessageBox.Show(abom2(x))

        Next

        Return abom2

    End Function

    Public Function DatatableToArray(ByVal dt As DataTable, ByVal intColomn As Integer) As String()
        Dim intRows As Integer = dt.Rows.Count
        Dim arrValues() As String = New String() {}
        Dim i2 As Integer
        For i2 = 0 To intRows - 1
            arrValues(i2) = dt.Rows(i2).Item(intColomn)

        Next

        Return arrValues

    End Function

End Class
Reply With Quote
  #6  
Old 11-03-2011, 06:19 PM
PlausiblyDamp's Avatar
PlausiblyDampDataSet Question... PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If only one source is coming directly from a database then datasets might not be the best solution to the problem.

It might be easier to define a class (classes) that represents the data structure (structures) you want and bind the grid to a List(Of ...) these classes. This way you could use DataSets or DataReaders to populate the classes from the SQL DB and simply create the non sql versions from the data you get from the PDM system.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DataSet Question...
DataSet Question...
DataSet Question... DataSet Question...
DataSet Question...
DataSet Question...
DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question... DataSet Question...
DataSet Question...
DataSet Question...
 
DataSet Question...
DataSet Question...
 
-->