|
-
Nov 21st, 2004, 10:22 AM
#1
Thread Starter
Frenzied Member
Adding A New Row to my DataSet :(
I'm trying to use the following code and it's giving me a big, big headache..
VB Code:
Dim NewRow As DataRow = DS.Tables("Users").NewRow
NewRow!UserName = txtUserName.Text
NewRow!Password = txtPassword.Text
NewRow!Type = "User"
DS.Tables("Users").Rows.Add(NewRow)
Dim CB As New OleDbCommandBuilder(DA)
DA.UpdateCommand = CB.GetUpdateCommand
DA.Update(DS, "Users")
This works just fine if i don't add the record
is there anything I need to do between adding the record and updating the thing? Thanks.
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Nov 21st, 2004, 01:45 PM
#2
Addicted Member
If you add the record what happen? Does your datatable have primary key? Does the Select command for the dataadapter return all rows? What the exception thrown, if any?
-
Nov 22nd, 2004, 12:02 AM
#3
Shouldn't you be getting an Insert Command instead?
-
Nov 22nd, 2004, 01:40 AM
#4
Thread Starter
Frenzied Member
Yes I probably should... could you give me some proper code on how to impliment the insertcommand stuff?
Thanks,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Nov 22nd, 2004, 01:51 AM
#5
Re: Adding A New Row to my DataSet :(
VB Code:
Dim NewRow As DataRow = DS.Tables("Users").NewRow
NewRow!UserName = txtUserName.Text
NewRow!Password = txtPassword.Text
NewRow!Type = "User"
DS.Tables("Users").Rows.Add(NewRow)
Dim CB As New OleDbCommandBuilder(DA)
DA.UpdateCommand = CB.GetInsertCommand()
DA.Update(DS, "Users")
Untested, of course.
-
Nov 22nd, 2004, 01:52 AM
#6
One more thing, please don't do this:
NewRow!UserName = txtUserName.Text
Instead, do this:
NewRow("UserName") = txtUserName.Text
-
Nov 23rd, 2004, 09:34 AM
#7
Thread Starter
Frenzied Member
I'm getting an error here...
VB Code:
Users.Conn.Open()
Dim NewRow As DataRow = Users.DS.Tables("Users").NewRow
NewRow("UserName") = txtUserName.Text
NewRow("Password") = txtPassword.Text
NewRow("Type") = "User"
Users.DS.Tables("Users").Rows.Add(NewRow)
Dim CB As New OleDbCommandBuilder(Users.DA)
Users.DA.UpdateCommand = CB.GetInsertCommand
[b] Users.DA.Update(Users.DS, "Users")[/b]
Users.Conn.Close()
MsgBox("Added New User!", MsgBoxStyle.OKOnly, "Success")
Me.DialogResult = DialogResult.OK
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
not telling me anymore than that
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Nov 23rd, 2004, 04:24 PM
#8
Hyperactive Member
You can get a bit more info on the error if you catch the exception in a Try....Catch... block.
Something like
VB Code:
Try
Users.DA.UpdateCommand = CB.GetInsertCommand
Users.DA.Update(Users.DS, "Users")
Catch ex as Exception
Messagebox.Show (ex.ToString)
End Try
Try that and then post the full exception message and then maybe we can help some more?
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|