Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add record from text boxes

Status
Not open for further replies.

Sandman83

Programmer
Sep 11, 2001
122
US
Hi All,

I am rather new to VB.Net 05 and am a little confused about this data binding thing. I have a built in db and a form with four text boxes. I want to take the information in the text boxes and create a record, then add that record to the db. I tried the following code, but it just gets ignored. No error, no new record, nothing.

Code:
Private Sub cmdExportAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExportAdd.Click
        Dim NewRecord As DataRow

        NewRecord = daACRE.Tables("ExportSites").NewRow
        NewRecord.Item(0) = txtExportSite.Text
        NewRecord.Item(1) = txtExportTNSName.Text
        NewRecord.Item(2) = txtExportUID.Text
        NewRecord.Item(3) = txtExportPWD.Text

        daACRE.ExportSites.Rows.Add(NewRecord)

        taExportSites.Update(daACRE.ExportSites)

        txtExportSite.Clear()
        txtExportTNSName.Clear()
        txtExportUID.Clear()
        txtExportPWD.Clear()

    End Sub

I know the code is being executed since the text boxes clear when I run it.

So my questions are:

1.) Is this approach the "right" approach? Or should I be doing this like I do with VBA/VB.Old (VB 6) and just make a data connection and execute a SQL statement.
2.) If this is a good approach, any ideas what I am missing?

P.S. I am attempting the above approach as I am trying to learn more about VB.Net. No point in learning a newer version of a language if you don't try and take avantage of it's "improvement". ;-)

Thanks for all help/feedback
 
It's the data adapter. Sorry, not really sure how else to answer.
 
Well, that lead me to my first issue. It's the data set, I just named it incorrectly.
 
And how did the dataset get filled with all the beautifull data you have for it?

Christiaan Baes
Belgium

My Blog
 
I created the database, which "automagically" created the dataset. Then with server explorer, I opened the database with "Show table data" and added a couple of records so that I would have something in it to verify I am connecting.
 
When you say "filled" you mean this line of code, right?

Code:
taExportSites.Fill(dsACRE.ExportSites)

I use this line of code for filling a listview with the existing data. It runs when ever the tab selection of my tab object is changed. Do I need to add it somwhere else?
 
automagically doesn't exist the wizard are bad and will get you into trouble sooner rather then latter. Does your table have a primary key?

Christiaan Baes
Belgium

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top