Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-02-2009
Member
 
Join Date: Jan 2009
Posts: 36
Temporary table in VB.NET

Hello friends,

I am developing an application where i want this VB.net application to accept the data from the user then store it in a table for temporary basis, Do some functions & when all done I want this table to store the data in a back-end database. After this again for a new user this temporary table will be empty & ready to accept the new data!

I don't know if this is possible or not in this way?

Any helps would be appreciated!
Reply With Quote
  #2  
Old 18-02-2009
Member
 
Join Date: Jan 2009
Posts: 22
Re: Temporary table in VB.NET

So you want a table to be displayed and then the table to be hidden?
If yes, then why not using the .visible = false?
Reply With Quote
  #3  
Old 18-02-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Temporary table in VB.NET

here is some example code for you... to give you an idea.

Code:
    'Create the table
        Dim Table1 As DataTable
        Table1 = New DataTable

        'Add columns to it
        Table1.Columns.Add("Id", Type.GetType("System.Int32"))
        Table1.Columns.Add("Name", Type.GetType("System.String"))

        'Add rows and fill with data
        Dim EditRow As DataRow
        EditRow = Table1.NewRow()
        EditRow(0) = 1
        EditRow(1) = "John"
        Table1.Rows.Add(EditRow)
        EditRow = Table1.NewRow()
        EditRow(0) = 2
        EditRow(1) = "Jane"
        Table1.Rows.Add(EditRow)

        'Create a dataset and add this table to it
        Dim DS As DataSet
        DS = New DataSet
        DS.Tables.Add(Table1)
So your dataset is ready

Code:
Sub SaveToFile()
        Dim StreamWR As FileStream
        'Check if the file is there.
        If File.Exists("C:\data.txt") Then
            StreamWR = New FileStream("C:\data.txt", FileMode.Append, FileAccess.Write)
        Else
            StreamWR = New FileStream("C:\data.txt", FileMode.CreateNew, FileAccess.Write)
        End If
        Dim FileWriter As New StreamWriter(StreamWR)
        Dim dr As DataRow
        Dim i As Int32
        For Each dr In ds.Tables("Table1").Rows
            For i = 0 To ds.Tables("Table1").Columns.Count - 1
                FileWriter.Write(dr(i) & vbTab)
            Next
            FileWriter.WriteLine("")
        Next
        FileWriter.Close()
        StreamWR.Close()
End Sub
Hope this example helps you to achive what you want to do! here i am saving the dataset to a file on hard disk! this you can do to save in a database as you never mentioned the database you are working with?
Reply With Quote
  #4  
Old 18-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Temporary table in VB.NET

I do this sort of thing all the time, but generally I create tables that
persist. If I need to truncate them, I do so. Sometimes I just delete then
by calling one sp and then rebuild them with another.

Here's a simple example, creating the 'nhtable' table:

Code:
Dim ocmdnh As SqlCommand

ocmdnh = New SqlCommand("exec sp_makenhtable", oconn)

ocmdnh.ExecuteNonQuery()

'open nhtable

Dim danhtable As New SqlDataAdapter("select * from nhtable", oconn)

Dim dsnhtable As New DataSet("nhtable")

danhtable.Fill(dsnhtable, "nhtable")

the sp sp_makenhtable deletes the table and then rebuilds it, and then fills
it with data; in sql server it looks like this:

CREATE PROCEDURE sp_makenhtable AS
if exists (select * from information_schema.tables where table_name =
'nhtable')
drop table nhtable
select imcacct, brname, addr, addr2, city, st, zip, draw, bundlect,
issuecode into nhtable from manifest where draw < 300


Sometimes the build is more sophisiticated, adding primary keys, indices,
etc. Sometimes I even delete and dynamically build the sp itself. I will
do this when the sp has variable needs that are not easily passed into the
sp itself. In that case, I will call it to create it and then call it again
to exec it:

Dim ocmd As SqlCommand

ocmd = New SqlCommand("exec sp_dropsp_buildbranchlistandtable", oconn)

ocmd.ExecuteNonQuery()

Dim creationstring As String

If glf_custstat = "" Then

creationstring = "CREATE PROCEDURE sp_buildbranchlist AS "

creationstring += " select imcacct, brname, addr, addr2, city, st, zip,
custstat into branchlist from branches"

creationstring += vbCrLf & "where imcacct in " & longstring

Else

creationstring = "CREATE PROCEDURE sp_buildbranchlist AS "

creationstring += " select imcacct, brname, addr, addr2, city, st, zip,
custstat into branchlist from branches"

creationstring += vbCrLf & "where imcacct in " & longstring & " and custstat
= '" & glf_custstat & Chr(39)

End If

Dim sqladapt As New SqlDataAdapter

sqladapt.SelectCommand = New SqlCommand(creationstring, oconn)

Try

sqladapt.SelectCommand.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

ocmd = New SqlCommand("exec sp_buildbranchlist", oconn)

Try

ocmd.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try
Let me know if you have questions about these approaches; I'll be glad to
help.
Reply With Quote
  #5  
Old 18-02-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Temporary table in VB.NET

TO create a table in Vb.net application (temporary) then storing to SQL server

Code:
Please try the following code:

    Private Sub BuildDataSet()

 

        Dim objDS As New Data.DataSet("CustomerOrders")

        Dim dtCustomers As Data.DataTable = objDS.Tables.Add("Customers")

        Dim dtOrders As Data.DataTable = objDS.Tables.Add("Orders")

        Dim objDR As Data.DataRow

 

        With dtCustomers

            .Columns.Add("CustomerID", Type.GetType("System.Int32"))

            .Columns.Add("FirstName", Type.GetType("System.String"))

            .Columns.Add("LastName", Type.GetType("System.String"))

            .Columns.Add("Phone", Type.GetType("System.String"))

            .Columns.Add("Email", Type.GetType("System.String"))

        End With

 

        With dtOrders

            .Columns.Add("CustomerID", Type.GetType("System.Int32"))

            .Columns.Add("OrderID", Type.GetType("System.Int32"))

            .Columns.Add("OrderAmount", Type.GetType("System.Double"))

            .Columns.Add("OrderDate", Type.GetType("System.DateTime"))

        End With

 

        objDS.Relations.Add("r_Customers_Orders", _

        objDS.Tables("Customers").Columns("CustomerID"), _

        objDS.Tables("Orders").Columns("CustomerID"))

 

        objDR = dtCustomers.NewRow()

        objDR("CustomerID") = 1

        objDR("FirstName") = "Miriam"

        objDR("LastName") = "McCarthy"

        objDR("Phone") = "555-1212"

        objDR("Email") = "tweety@hotmail.com"

        dtCustomers.Rows.Add(objDR)

 

        objDR = dtOrders.NewRow()

        objDR("CustomerID") = 1

        objDR("OrderID") = 22

        objDR("OrderAmount") = 0

        objDR("OrderDate") = #11/10/1997#

        dtOrders.Rows.Add(objDR)

 

        Console.WriteLine(objDS.GetXml())

 

    End Sub
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Temporary table in VB.NET"
Thread Thread Starter Forum Replies Last Post
Unable to work with table columns in opera browser when the table has wide layout Janya Technology & Internet 5 27-08-2011 10:53 AM
Link a Table to another Table to Drop Down In Main Table himeshRES Windows Software 6 11-12-2010 02:01 PM
Colonizing a table of employees from a table of applicants in Microsoft Access laplapye Windows Software 4 30-11-2010 03:01 AM
Writing temporary table problem Jabeena Software Development 4 13-02-2010 12:20 PM
how to create sql temporary table for xml format using vb.net runet Software Development 3 31-03-2009 08:28 AM


All times are GMT +5.5. The time now is 09:41 AM.