Results 1 to 2 of 2

Thread: sql database update in vb.net

  1. #1
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sql database update in vb.net

    I am writing a vb.net and sql database program and can't figure out how to update the actual database. The 'dataset' is updated in a millisecond and I can view that just fine in my datagrid, but then when I restart the program.. the actual database was never updated and I'm starting all over. Any help would be great! God bless

    peace,
    mark

  2. #2
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default correction..

    I found on the microsoft website this code to perform the task I'm attempting:

    Code:
                ' Modify the following code to correctly connect to your SQL Server.
                sConnectionString = "Password=jC13942;User ID=budget;" & _
                                    "Initial Catalog=BudgetDB;" & _
                                    "Data Source=(local)"
    
                Dim objConn As New SqlConnection(sConnectionString)
                objConn.Open()
    
                ' Create an instance of a DataAdapter.
                Dim daTransactions As New SqlDataAdapter("SELECT * FROM transactions", objConn)
    
                ' Create an instance of a DataSet, and retrieve data from the Authors table.
                Dim dsBudgetDB As New DataSet("BudgetDB")
                daTransactions.FillSchema(dsBudgetDB, SchemaType.Source, "transactions")
                daTransactions.Fill(dsBudgetDB, "transactions")
    
                'subtract textbox amount from appropriate category and report to 'database'
                If TitheRdo.Checked = True Then
                    'Form1.TitheSpent = Double.Parse((Double.Parse(Form1.TitheSpent)) + (Double.Parse(TextBox1.Text)))
                    'Form1.Trans(Form1.TransCtr) = "Tithe Spent: $" + TextBox1.Text
                    'Form1.TransCtr += 1
                    'TransactionsTableAdapter1.Insert(Trans1.ctr,"Tithe",Date.Today,Double.Parse(TextBox1.Text),'check',0)
    
                    ' Create a new instance of a DataTable.
                    Dim tblTransactions As DataTable
                    tblTransactions = dsBudgetDB.Tables("transactions")
    
                    Dim drCurrent As DataRow
                    ' Obtain a new DataRow object from the DataTable.
                    drCurrent = tblTransactions.NewRow()
    
                    ' Set the DataRow field values as necessary.
                    drCurrent("transID") = Form1.TransCtr
                    drCurrent("category") = "Tithe"
                    drCurrent("date") = Date.Today
                    drCurrent("amount") = Double.Parse(TextBox1.Text)
                    drCurrent("currency") = "check"
                    drCurrent("cleared") = 0
    
                    'Pass that new object into the Add method of the DataTable.Rows collection.
                    tblTransactions.Rows.Add(drCurrent)
                    MsgBox("Add was successful.")
    I get an exception every time saying that the default settings for sql server don't allow remote connections.. but I've already adjusted that in the sql server surface area configuration. Any ideas?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •