.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SqlDataAdapter Demonstration

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

I need a demonstration of

  • Data Relationship between tables
  • UpdateCommand of sqlDataAdapter
  • DeleteCommand of sqlDataAdapter
  • InsertCommand of sqlDataAdapter

That means managing data using dataset and merging changes made through and updating database using DataAdapter

View Complete Post

More Related Resource Links

Stored Procedures & SqlDataAdapter not updating a calendar control


Hi all,

I have a database linked to a calendar. I had a peice of code that retrieved dates from a database and populated the calendar. I wanted to tidy up my code using stored procedures (they seem neater & i assume there's a benefit somewhere). so i came up with this, however it's not working. The calendar displays, but it's not being populated with the database entries. The SqlCommand & SqlParameter I have working elsewhere in my code; as with the SqlDataAdapter (which also worked before i tried to conver to a stored procedure!) but combining these three (SqlCommand, SqlParameter & SqlDataAdapter) seem to be causing me problems.

It's probably something stupid but if someone could take a look and point me in the right direction, I'd be very grateful.


Public Sub dbConnection()
        dbConnString = ConfigurationManager.ConnectionStrings("connString").ConnectionString
        sqlConn = New SqlConnection(dbConnString)
    End Sub

Public Sub EquipmentDDLSelection()

        Dim dbCMD As New SqlCommand("PopulateCalendar", sqlConn)
        dbCMD.CommandType = CommandType.StoredProcedure

        Dim parameterBookedEvents As New SqlParameter("@bookedEvents", SqlDbType.VarChar, 50)

SqlDataAdapter.Update related tables



I would like to get 2 related tables from SQL Server to DataSet, insert new rows and save them back to SQL Db.

Let's say i have 2 related tables as shown below...

Table1 Table2
test1ID (Primary Key) test2ID (Primary Key)
data test1ID


In Sql i have Diagram with relationship and Update Rule is set to Cascade

I am trying to get them to dataset, insert "master" and "child" row and save them back to db.

I tried different approaches (none of them workes) and this is one of them:

Dim ds As New DataSet()
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("NastanitveConnectionString").ConnectionString)
        Dim sql As String = "SELECT * from Table1;Select * from Table2;"
        Dim d

SQLDataAdapter/SQLDataReader takes lot of time for executing a query

All, I have a webpage with 6 drop down lists. User can start with selecting any drop down list first, and then proceed in any order.  1. Assume when the 1st dropdown is selected first, rest 5 drop downs (except 1st) are filtered/updated based on the selected value in the 1st dropdown. 2. Assume user selects the 4th dropdown second, rest 5 drop downs (except 4th) will be filtered/updated but the condition would be based on both 1st drop down and 4th drop down. But while filtering the first drop down, only the 4th drop down is used as filter (self-filter will be ignored). The code works fine but I see a very bad performance hit in time when the user selects the fourth dropdown after selecting three drop downs. I tried using both SQLDataAdapter and SQLDataReader but neither used to solve the issue. The code takes a lot of time on one line in either of the code (which is highlighted below). When I run the query in SQLServer Mgmt Studio, the query completes in a few seconds.Using SQLDataReader: SqlConnection conn = new SqlConnection(CONNECTION); SqlCommand ObjCmd = new SqlCommand(query, conn); ObjCmd.CommandTimeout = 600; conn.Open(); SqlDataReader daSelTools = ObjCmd.ExecuteReader(); //This line takes a lot of time ddl.Items.Clear(); // Call Read before accessing data. while (daSelTools.Read()) { ddl.Items.Add(new ListItem(String.Format("{0}",daSelTools[0])));

sqldataadapter problem

I am getting the following error when I use odbc to connect to sql server. How can I solve this ??   The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid arguments   Here is my code :               private void listdata()         {                       OdbcConnection myConnection = new OdbcConnection("Driver={SQL Server};Server=server;UID=userid;PWD=password;Database=newdb;");             string liststring;             OdbcCommand listcmd = new OdbcCommand(liststring, myConnection);             BindingSource bsource = new BindingSource();             try             {                   //MessageBox.Show(this, "asdfasdf", "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);                 if (listBox1.SelectedItem.ToString() == "Arrival")                     liststring = "select top 10 column

ExecuteNonQuery using stored procedure will not delete record (SQLDataAdapter)

Hi all I'm using VB.net 2.0 with a SQL server (2005) backend db. I've got a very odd problem. I'm trying to use a stored procedure with a parameter to delete a record from a table. I've tested the stored procedure by running it directly from visual studio and it works fine, but when running it through my application nothing happens. There's no error and it appears to have worked but the record is not deleted. I've checked permissions on the backend db and giving the network ASPNet account the db owner role has no effect either. Here's the code, there are 3 layers - the webform code, then the business logic class, then the dataconnection class. 'firstly the original code that is run from the webform when the user selects to delete the record Partial Public Class NewPerson     Inherits System.Web.UI.Page    Private newConn As New DBConnection    Private currentNewRequest As New NewRequest(newConn)     Protected Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click     Dim requestID As Integer = CInt(Me.lblRecordID.Text)    Me.currentNewRequest.newRequestID = requestID    Me.newConn.openConnection()    Me.currentNewRequest.DeleteRecord()    Me.newConn

Timeout when calling SqlDataAdapter.Fill(DataSet)

This issue has stumped me for a while.  Hopefully someone here can give me some insight. When my site runs the following code it works just fine 99% of the time. Dim sda As New Data.SqlClient.SqlDataAdapter(cmd) Dim ds As New Data.DataSet Try sda.Fill(ds) Catch ex As Exception ... The command is calling a SQL Server 2005 stored procedure that takes 20 parameters and returns 6 tables of about 5-50 rows each. The paramters are all NVARCHAR, INT, or BIT data types.  Only one of the parameters is Input/Output. There is a total of about 100 rows returned. Normally this takes a fraction of a second, but for some queries, it times out after 30 seconds. When I run the exact same query in the Management Studio query window it takes 1 second. Any idea what I can do to get the same performance from .Net as I am getting from Management Studio?

foreach loop and SqlDataAdapter to update WHERE UserId = UserId ?


I'm trying to figure out how to update multiple rows in my Directory table, when a user changes their Street Number or Street Name in their profile.  They can add multiple users to a directory and each user they add to the directory has this primary users UserId in it. So if the primary user changes their address, I want it to update the address for all the users they listed in the directory as well. I'm adding this to the On_Click in the Code Behind, so when they click to update their profile, it fires this function as well.

This code may be way off, but here's what I have right now:

                //Update directory user addresses for this account, if profile address has changed
                if ((currentStreetNumber != creatingStreetNumber) || (currentStreetName != creatingStreetName))
                    string myDirectoryConnection = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                    SqlDataAdapter cmd2 = new SqlDataAdapter("Update Directory SET [StreetNumber] = @StreetNumber, [StreetName = @StreetName] WHERE [UserId] = @UserId", myDirectoryConnection);
                    cmd2.UpdateCommand.Parameters.Add("@UserId", currentUserId.ToString());

Can I download 2010 "Information Worker Demonstration and Evaluation Virtual Machine (RTM) " on my l



I want to setup Sharepoint server 2010 on my windows 7 home premium laptopn. Can I download 2010 Information Worker Demonstration and Evaluation Virtual Machine (RTM) on my laptop.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend