View Full Version : sql database update in vb.net

12-04-2007, 02:57 AM
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


12-04-2007, 03:41 AM
I found on the microsoft website this code to perform the task I'm attempting:

' 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)

' 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

' 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.
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?