saving file to sql server.

Hi,

I couldn't update my data table.
Everytime I debug my program, it's added into data table and show data successfully.
When I exit my application, everything turned empty.

Try
Me.Validate()
Me.CustomersBindingSource.EndEdit()
Me.CustomersTableAdapter.Update(Me.NorthwindDataSet.Customers)
MsgBox("Update successful")

Catch ex As Exception
MsgBox("Update failed")
End Try




Answer this question

saving file to sql server.

  • Danny Tuppeny

    lookup,

    Generally speaking, when you create a DataTable in DataSet, the table is stored in memory but not the real DBMS SQL Server. When you would like to modify your datatable, just use the DataAdapter. After the change in rows or columns, please don't forget to make the DataSet update. Here I have a code example from one of my project that show a method to update you DataSet:

    Private Sub UpdateDataSet()

    Dim strSQL As String

    Dim strConn As String

    Dim objDA As SqlClient.SqlDataAdapter

    Dim objDS As New Data.DataSet()

    Dim objCB As SqlClient.SqlCommandBuilder

    Dim objRow As Data.DataRow

    Dim intCounter As Integer

    Dim strResult As String

    'Build the SQL and Connection strings

    strConn = "Initial Catalog=pubs;Data Source=(local);Integrated Security=SSPI;"

    strSQL = "SELECT * FROM authors"

    'Initialize the SqlDataAdapter with the SQL

    'and Connection strings

    objDA = New SqlClient.SqlDataAdapter(strSQL, strConn)

    'Initialize the SQLCommandBuilder by passing in

    'our DataAdapter. This will build the INSERT, UPDATE,

    'and DELETE commands for the DataAdapter object.

    objCB = New SqlClient.SqlCommandBuilder(objDA)

    'Use the SqlDataAdapter to fill the DataSet with

    'the authors table

    objDA.Fill(objDS, "Authors")

    'Add a new author to the local table in memory

    objRow = objDS.Tables("Authors").NewRow

    objRow("au_id") = "335-22-0707"

    objRow("au_fname") = "Tim"

    objRow("au_lname") = "McCarthy"

    objRow("phone") = "760-930-0075"

    objRow("contract") = 0

    objDS.Tables("Authors").Rows.Add(objRow)

    'Write the update back to the server

    objDA.Update(objDS, "Authors")

    'Indicate success

    Console.WriteLine("New author added!")

    Console.ReadLine()

    objDS.WriteXmlSchema("test.txt")

    Console.ReadLine()

    With objDS.Tables(0)

    'Loop through the records and print the values

    For intCounter = 0 To .Rows.Count - 1

    strResult = .Rows(intCounter).Item("au_fname").ToString _

    & " " & .Rows(intCounter).Item("au_lname").ToString

    Console.WriteLine(strResult)

    Next

    Console.ReadLine()

    End With

    End Sub



  • Martin Knotek

  • ClydeFrog


    Hello Bruno,

    This is a newbie question.

    I have a textbox and I just want to create a record in a sql 2005 express table for the value in that textbox. Just one column for one record.

    It seems like in the above you are copying the contents of the table to memory, insert a new record and then update that change to the sql table. Is this correct

    Is there any way to just direct insert the new record to the sql table Could you show me a sample

    Thanks,
    Nelson

  • saving file to sql server.