We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem in Updating a Table

I wanna just a beginning for my coding. (The application running with VB.NET and SQL server) I did this code and it not shown any error. After this process it is displayed the message "Successfully updated". But data is not update on the table. Please tell me, how to update the table?

This is my code....

    Dim conStr As String
    conStr = "Data Source=MY-PC\SQLEXPRESS;Initial Catalog=MyAccounts; Integrated Security=True"
    Dim objConn As New SqlConnection(conStr)
    objConn.Open()

    Dim DAaccounts As New SqlDataAdapter("Select * From Accounts", objConn)

    Dim DSmyAcc As New DataSet("MyAccounts")
    DAaccounts.FillSchema(DSmyAcc, SchemaType.Source, "Accounts")
    DAaccounts.Fill(DSmyAcc, "Accounts")

    Dim tblAcc As DataTable
    tblAcc = DSmyAcc.Tables("Accounts")

    Dim drCurrent As DataRow
    drCurrent = tblAcc.NewRow()

    drCurrent("Acc_ID") = 200
    drCurrent("Acc_Name") = "Test Acc"

    tblAcc.Rows.Add(drCurrent)
    MsgBox("Add was successful.")
    objConn.Close()
2
Contributors
3
Replies
23 Hours
Discussion Span
9 Months Ago
Last Updated
4
Views
weeraa
Junior Poster in Training
60 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Which table are you referring to exactly? The tblAcc, the Accounts table in the dataset or the database table? Because you have no code that will alter the last two. Your code to add a row to tblAcc looks right so how are you checking that tblAcc has no new rows?

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

First of all thank you for the reply hericles.

Database : MyAccounts
Table : Accounts

If I tell basically, I just want to add new row to database table. Cant i do it with this code?

weeraa
Junior Poster in Training
60 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Yes, you can. If you are using a dataAdapter you can specify its update, insert and delete commands so that changes to the dataset can be persisted to the database. Check out the MSDN article to learn more: http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.update.aspx

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1381 seconds using 2.71MB