?
Solved

Starting with VB.net & ADO.Net

Posted on 2004-10-03
2
Medium Priority
?
189 Views
Last Modified: 2010-04-23
Hi

I'm just starting out with VB.net and ADO.net.  Although I'm getting everything to work, the code seems very long winded.  For instance this is my code to check the number of records in a dataset set table and add a blank record if it is 0.
'
  Dim intRecCount As Integer
        OleDbDataAdapter1.Fill(MemberDataSet1)
        intRecCount = Me.BindingContext(MemberDataSet1, "Members").Count
        If intRecCount = 0 Then
            Dim dr As DataRow
            dr = MemberDataSet1.Tables("Members").NewRow
            MemberDataSet1.Tables("Members").Rows.Add(dr)
            Me.BindingContext(MemberDataSet1.Tables("Members")).EndCurrentEdit()
            OleDbDataAdapter1.Update(MemberDataSet1.Tables("Members"))
        End If
'
It works Ok but it seems a lot of code.  This is just an example - all the code I'm generating seems as complex.  Am I missing something?

0
Comment
Question by:Petermcg001
2 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 150 total points
ID: 12213668
Hi Petermcg001:
What about removing the binding part of it?

This is slightly shorter:

 Dim intRecCount As Integer
        OleDbDataAdapter1.Fill(MemberDataSet1)
        intRecCount = MemberDataSet1.Tables(0).Rows.Count
        If intRecCount = 0 Then
            Dim dr As DataRow
            dr = MemberDataSet1.Tables(0).NewRow
            MemberDataSet1.Tables(0).Rows.Add(dr)
            OleDbDataAdapter1.Update(MemberDataSet1)
        End If

Another alternative is to use a command object with the appropriate INSERT SQL statement instead

    If intRecCount = 0 then
        Dim cm As New OleDb.OleDbCommand("INSERT INTO Members .....", cn)
        cm.ExecuteNonQuery()
    End IF

Dabas
0
 
LVL 4

Expert Comment

by:VIkasumit
ID: 12216123
Hi..

The Alternative Option is what i use most.

When you just want to need to insert the data in the table than better use the xxxCommand object than using the Dataset it is good if you want ot Dispaly data and for select querys with some data otherwise better use the xxxCommand Object for select Max, min ave, or Insert, update and than refresh your dataset for display is what i use though not very sure how good it is in terms of the Speed on server and bandwidth utilization if run on Client server arctiechture.... but run ine on single machine or even if only about 100 user are using your program at one time

VIkasumit
www.sumitonnet.20m.com
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question