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()
Related Article: Problem with updating records
is a solved VB.NET discussion thread by Wolxhound90 that has 10 replies and was last updated 1 year ago.
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
hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9