Need temp table with values hard coded

  • Thread starter Thread starter Angelflower
  • Start date Start date
A

Angelflower

Guest
Hello,

I am new to VB.Net development using Visual Studio 2013 and finding it very different from developing in MS Access. So for my 1st project I am developing a Windows Forms Application that takes in two parameters used to query a table on the SQL server and then displays the results in a dataviewgrid. My form has a button on it that can then be click and export results to a spreadsheet. All this works great! Yeah! The problem is that in my original SQL code there are two temp tables in the middle of it where I am manually adding values for two of the fields based on a matching identifier in each table. One temp table has 10 rows in it but the other temp table has over 1400 rows. I am not sure how to add these two temp tables and then populate my dataset.

Here is the code for EventStatsDataSet.xsd (parent table) that is pulled directly off the SQL server using the TableAdapter Configuration Wizard:

Select tblEvent.CallID, tblEvent.Sequence, tblEvent.StateType, tblEvent.State, tblEvent.DataForm, tblEvent.DataID, tblEvent.Data, tblEvent.EventDateTime, as Verbiage

from tblEvent with (NoLOck)

This is the code that I am using to populate the main datagridview when the OK button is pushed:

Try

Me.TblEventTableAdapter.CVTFill(Me.EventStatsDataSet.tblEvent, CType(txtEventDateTime.Text, Date), "%" & txtMemberID.Text & "%")

Catch ex As System.Exception

System.Windows.Forms.MessageBox.Show(ex.Message)

End Try


If Me.TblEventDataGridView.RowCount = 1 Then

MessageBox.Show("No results found. Please check your criteria and then try again.")

End If

For the field Verbiage I am using a separate module that creates a datatable named tblEventDataDescr.

Sub Main()

Get a DataTable instance from helper function.

Dim tblEventDataDescr As DataTable = GetEventDataDescr()

End Sub


Function GetEventDataDescr() As DataTable


Create four typed columns in the DataTable.

EventDataDescr.Columns.Add("DataID", GetType(Integer))

EventDataDescr.Columns.Add("DataIDLookup", GetType(String))

EventDataDescr.Columns.Add("Description", GetType(String))


Add rows with those columns filled in the DataTable.

EventDataDescr.Rows.Add(1, "2339", "Random Text")

And so on….

Return EventDataDescr

End Function


On my user form when the OK button is pushed I am able to populate another DataGridView 1 with this:

Get a DataTable instance from helper function.

Dim tblEventDataDescr As DataTable = GetEventDataDescr()

DataGridView1.DataSource = tblEventDataDescr


But really what I need is update the 1st dataset with the value from the tblEventDataDescr.Description based on the one-to-many relationship I need to create between the tblEventTableAdapter.DataID and tblEventDataDescr.DataIDLookup.

I tried to create the tblEventDataDescr on the EventStatsDataSet.xsd designed but I wasn’t able to figure out how to add my data to it since that is hard coded in the module.

Thanks in advance for your help!

Continue reading...
 
Back
Top