Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.net 2010 creating and using a dataset and SQLdata adapter example

Posted on 2013-10-25
4
Medium Priority
?
527 Views
Last Modified: 2013-10-25
Dear experts,

I need to use a dataset to add or update update a table with about 100 000 recs from a SQL 2008 server.

Can you please assitance to my example and show me how to complete complete this approach to view data and modify data?

Dim conn As New SqlConnection
        conn.ConnectionString = My.Settings.XXXX      
 conn.Open()
        Dim ds As New DataSet("Claims")
        Dim cmd As New SqlCommand("Select * from claim where claim.claimID ='" & txtClaimId.Text & "'", conn)
        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        da.Fill(ds)
        txtCompany
       txtCompName
        txtloc......


Thanks
Cj
0
Comment
Question by:cin_champ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 2000 total points
ID: 39600604
This should get you started

        Dim cnSQL As SqlConnection = Nothing
        Dim cmdSQL As SqlCommand
        Dim daSQL As SqlDataAdapter
        Dim dsData As DataSet = Nothing

        cnSQL = New SqlConnection()
        cnSQL.ConnectionString = YOURCONNECTIONSTRING

        Try
            cnSQL.Open()
        Catch ex As Exception
            cnSQL.Dispose()
            cnSQL = Nothing
        End Try

        cmdSQL = New SqlCommand()
        cmdSQL.Connection = cnSQL
        cmdSQL.CommandText = 'YOUR SELECT STATEMENT
        cmdSQL.CommandType = CommandType.Text

        dsData = New DataSet()
        Try
            daSQL = New SqlDataAdapter(cmdSQL)
            daSQL.Fill(dsData)
            daSQL.Dispose()
        Catch ex As Exception
            dsData.Dispose()
            dsData = Nothing
        Finally
            cmdSQL.Dispose()
            cnSQL.Close()
            cnSQL.Dispose()
        End Try

        Return dsData

Open in new window

0
 

Author Comment

by:cin_champ
ID: 39600645
Dustock ,

thanks for the response but  need to know how to I link my text boxes to the dsData?

txtCompany = ?
txt customername = ?

Thanks
Cj
0
 
LVL 9

Assisted Solution

by:dustock
dustock earned 2000 total points
ID: 39601129
Sorry about that, I thought you had that part covered.  Just an FYI, the code above was intended to be a subroutine, and actually the connection could be its own subroutine, but we wont get into that right now.  If you aren't putting the above code in a subroutine remove the 'return dsData" and replace with the code below.

In the example below the (0)(0) is first row, first column and (0)(1) is first row, second column.  The commented out the lines do the exact same thing, but I replaced Tables(0) with Tables("tablename"), and I guessed at the database column names after the row(0).  

Let me know if I can be of anymore help.

        If dsData.Tables(0).Rows.Count > 0 Then
            txtCompany.Text = dsData.Tables(0).Rows(0)(0).ToString();
            txtcustomername.Text = dsData.Tables(0).Rows(0)(1).ToString();
            'txtCompany.Text = dsData.Tables("claim").Rows(0)("Company").ToString();
            'txtcustomername.Text = dsData.Tables("claim").Rows()("Name").ToString();
        Else
            MessageBox.Show("No data returned from query")
        End If

Open in new window

0
 

Author Closing Comment

by:cin_champ
ID: 39601456
Thank You!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

618 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