Home Page
"Join my free Amazing ASP.NET newsletter"
It's safe and easy to signup. You get:
  • Notified anytime a new article comes out
  • Technical step-by-step tutorials on all important ASP.NET topics
  • Expert guidance so you can reach unlimited ASP.NET success
  • Important ASP.NET news updates
Enter your Email

Category: ADO.NET

Click here to download the source code for this lesson.  When you open the project files, set GridView_SQLServer.aspx as the Start Page.

This lesson builds on the knowledge of a some prior lessons.  Here are the links to those lessons:
How to use ADO.NET with parameters in ASP.NET to Query a SQL Server database
How to use ADO.NET with parameters in ASP.NET to UPDATE a record in a SQL Server database

In those lessons I covered how to use the ADO.NET SqlCommand and SqlParameter classes (along with the SqlDataAdapter) to run SQL query and update operations with parameters against an SQL Server database table.  If you haven’t read those lessons yet, it is important to do so because they are the foundation for this lesson.  The code for this lesson also builds on the code from the prior lessons.

In this lesson, I am going to cover how to use the ADO.NET SqlCommand and SqlParameter classes to execute an SQL Insert query with parameters against an SQL Server database table.  This lesson applies to ASP.NET with C#.

Why would you need to execute an SQL Insert operation and use parameters?
The answer is whenever you need to create a new record in the database.  You need a way to pass some data values for the table columns.  The data values are passed using parameters.

Let me get started.  First the business requirements.  In the prior lessons I had created a couple of web forms named GridView_SQLServer.aspx and Customer_Edit.aspx.  Those forms display records from a SQL Server database table named “Customer” and allow the user to modify the records.

I have a new requirement which states I must also allow the creation of new data in the table Customer.  In order to do that I am going to create a new web form named Customer_Insert.aspx.  This new web page will be responsible for giving the user the ability to enter data for a brand new record in the database.

I will put three TextBox controls on the form for the database fields First Name, Last Name and E-mail Address.  I will also put a Save Button control that will create the new record in the database when clicked.  Let me show you the code for that button so you can see how an ADO.NET SQL Insert is performed with C# and then I will discuss each block of code separately.

string first_name = txtFirstName.Text;
string last_name = txtLastName.Text;
string email = txtEmail.Text;

SqlCommand dbcmd = new SqlCommand();
SqlParameter dbparam = null;

using (SqlConnection dbconn = new SqlConnection(
 "Server=localhost;"
 + "Database=csharpuniversity;"
 + "User ID=sa;"
 + "Password=Sqlserverpass$123;"
 + "Trusted_Connection=False;"))
{
    string SQLInsert = "insert into [customer] "
 +" (first_name, last_name, email_address) VALUES (";

    SQLInsert += "@first_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "first_name";
    dbparam.Value = first_name;
    dbcmd.Parameters.Add(dbparam);

    SQLInsert += ",@last_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "last_name";
    dbparam.Value = last_name;
    dbcmd.Parameters.Add(dbparam);

    SQLInsert += ",@email )";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "email";
    dbparam.Value = email;
    dbcmd.Parameters.Add(dbparam);

    dbcmd.CommandText = SQLInsert;
    dbcmd.Connection = dbconn;
    dbconn.Open();
    dbcmd.ExecuteNonQuery();
}

If you read through the prior lesson about ADO.NET SQL Updates, you will notice that the code is very similar to this set of code that performs and SQL Insert.  In fact, it is almost identical.  Now let’s go through each block of code in more detail.

First I get the data entered by the user into the TextBox controls on the web form.

string first_name = txtFirstName.Text;
string last_name = txtLastName.Text;
string email = txtEmail.Text;

After that, inside the using { } block, I start setting up my Insert operation.

    string SQLInsert = "insert into [customer] "
 +" (first_name, last_name, email_address) VALUES (";

    SQLInsert += "@first_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "first_name";
    dbparam.Value = first_name;
    dbcmd.Parameters.Add(dbparam);

Notice that I created a string variable named SQLInsert that will be progressively built over several lines of code.  I have three pieces of information that I need to save to the database: the customer’s first name, last name and e-mail address.  That means that I need three SqlParameter objects.  You can see above that I create the first SqlParameter for the first_name column.  Remember from the prior lessons that in an SQL operation, you can use the @ symbol to specify a parameter like @first_name.  That allows ADO.NET to dynamically substitute a value for the variable @first_name at runtime.
For Oracle, you can use the : (colon) symbol to specify an ADO.NET parameter.  So if you were using Oracle as your database, you would change @first_name to :first_name.

When you are creating SqlParameter objects, you need to specify the data type, the name of the database column you want to create data for and the new value for the column.  Then you have to add the SqlParameter to the Parameters collection in the SqlCommand object that you are using.

I have to also create the SqlParameter objects for the other database columns last_name and email_address.

    SQLInsert += ",@last_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "last_name";
    dbparam.Value = last_name;
    dbcmd.Parameters.Add(dbparam);

    SQLInsert += ",@email )";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "email";
    dbparam.Value = email;
    dbcmd.Parameters.Add(dbparam);

So that makes a total of three SqlParameter objects that I created.

Next to finish off the code for the Save button, there are four lines of code left.

    dbcmd.CommandText = SQLInsert;
    dbcmd.Connection = dbconn;
    dbconn.Open();
    dbcmd.ExecuteNonQuery();

In those final lines of code I assign the text string for the Insert to the SqlCommand object dbcmd and associate the SqlConnection object with the dbcmd.  Then notice that I explicitly open the connection.  If you remember from the prior lessons, when I was using the SqlDataAdapter class, I didn’t need to open the connection because the SqlDataAdapter does that automatically.  When you are not using the SqlDataAdapter like in this lesson, you have to explicitly open the connection because the SqlCommand object doesn’t do that automatically.  The last line of code is a call to the ExecuteNonQuery() method of the SqlCommand class.

ExecuteNonQuery() is used whenever you want to run a database operation and you are not expecting back any data.  Examples of when you can use ExecuteNonQuery are when you need to execute SQL Update, Insert or Delete operations.

That wasn’t so hard was it?

You can think of the entire development process of using parameterized ADO.NET Insert operation as follows:
1) Specify your SQL Insert statement and use the @ symbol where SqlParameter variables are needed.  If you are using Oracle, us the : (colon) symbol to prefix the SqlParameter variable name.
2) Create each SqlParameter object and assign it a name, a type and a value.  You can create multiple SqlParameter objects if you need more than one variable in the Insert operation.
3) Associate the SqlConnection object with the SqlCommand object.
4) Open the SqlConnection object.
5) Run the ExecuteNonQuery() method of the SqlCommand object.
Take a look at this video that shows me Inserting an SQL Server database record with ADO.NET in ASP.NET.

Stay tuned for the next lesson where I’m going to show you how to Delete a database record using ADO.NET with parameters in ASP.NET.

Category: ADO.NET

Click here to download the source code for this lesson.  When you open the project files, set GridView_SQLServer.aspx as the Start Page.

This lesson builds on the knowledge of a prior lesson entitled “How to use ADO.NET with parameters in ASP.NET to Query a SQL Server database“.  In that lesson I covered how to use the ADO.NET SqlCommand and SqlParameter classes (along with the SqlDataAdapter) to run an SQL query with parameters against an SQL Server database table.  If you haven’t read that lesson yet, it is important to do so because it is the foundation for this lesson.  The code for this lesson also builds on the code from the prior lesson.

In this lesson, I am going to cover how to use the ADO.NET SqlCommand and SqlParameter classes to execute an SQL Update query with parameters against an SQL Server database table.  This lesson applies to ASP.NET with C#.

Why would you need to execute an SQL Update operation and use parameters?
The answer is whenever you need to modify or update a record in the database.  You need a way to pass some data values for the table columns.  The data values are passed using parameters.  You also need a way to execute the SQL Update with a “where” clause so that you can specify exactly which database record you are interested in modifying.  The where clause values are passed using parameters.

Let me get started.  First the business requirements.  In the prior lesson I had created a web form named Customer_Edit.aspx.  That form displays a specific record in a SQL Server database table named “Customer”.

I had a requirement which states I must allow Editing (or Updating) of the records in the Customer table.  In the web form Customer_Edit.aspx I had added some TextBox controls to hold the data from the Customer table.  I also added a Save button that will give the user the ability to update the information back to the database table. 

In this lesson I’m going to show you how to program the Save button Click event.  In order to do that, let’s do a quick review from the prior lesson.  Here is what Customer_Edit.aspx does in sequence:
1) GridView_SQLServer.aspx displays a list of records from the Customer table.
2) The user clicks on a hyperlink for a specific record.  The GridView_SQLServer.aspx page opens the Customer_Edit.aspx page and passed it some data using a QueryString variable:
Customer_Edit.aspx?customerid=55
3) The Customer_Edit.aspx page opens and the Page_Load event executes.  In the Page_Load method, the data for a specific customer is retrieved from the database and the TextBox controls on the page are populated with their corresponding data values.

Now I have to create code for a new step #4:
4) The user modifies the data in the TextBox controls and clicks Save.  The information is updated back to the database.

Let me show you what the code looks like for the Save button click event and then I will explain it in more detail.

string first_name = txtFirstName.Text;
string last_name = txtLastName.Text;
string email = txtEmail.Text;

string sCustomerId = Request.QueryString["customerid"];
int customerid = int.Parse(sCustomerId);

SqlCommand dbcmd = new SqlCommand();
SqlParameter dbparam = null;

using (SqlConnection dbconn = new SqlConnection(
 "Server=localhost;"
 + "Database=csharpuniversity;"
 + "User ID=sa;"
 + "Password=Sqlserverpass$123;"
 + "Trusted_Connection=False;"))
{
    string SQLUpdate = "update [customer] set ";

    SQLUpdate += "first_name = @first_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "first_name";
    dbparam.Value = first_name;
    dbcmd.Parameters.Add(dbparam);

    SQLUpdate += ",last_name = @last_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "last_name";
    dbparam.Value = last_name;
    dbcmd.Parameters.Add(dbparam);

    SQLUpdate += ",email_address = @email ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "email";
    dbparam.Value = email;
    dbcmd.Parameters.Add(dbparam);

    SQLUpdate += " where customer_id = @customer_id";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.Int32;
    dbparam.ParameterName = "customer_id";
    dbparam.Value = customerid;
    dbcmd.Parameters.Add(dbparam);

    dbcmd.CommandText = SQLUpdate;
    dbcmd.Connection = dbconn;
    dbconn.Open();
    dbcmd.ExecuteNonQuery();
}

So let’s walk through each of the blocks of code together.  First I get the data entered by the user into the TextBox controls on the web form.

string first_name = txtFirstName.Text;
string last_name = txtLastName.Text;
string email = txtEmail.Text;

Then I get the unique identifier for the record that I need to update in the database.  The database table Customer that I’m trying to update, has a customer_id column that contains an Identity value (a SQL Server automatically incremented number).  The customer_id is the unique identifier of a Customer record.  I can get this value from the QueryString since it is being passed to the page.  Here is how I get the value.

string sCustomerId = Request.QueryString["customerid"];
int customerid = int.Parse(sCustomerId);

After that, inside the using { } block, I start setting up my Update operation.

    string SQLUpdate = "update [customer] set ";

    SQLUpdate += "first_name = @first_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "first_name";
    dbparam.Value = first_name;
    dbcmd.Parameters.Add(dbparam);

Notice that I created a string variable named SQLUpdate that will be progressively built over several lines of code.  I have three pieces of information that I need to save to the database: the customer’s first name, last name and e-mail address.  That means that I need three SqlParameter objects.  You can see above that I create the first SqlParameter for the first_name column.  Remember from the prior lesson that in an SQL operation, you can use the @ symbol to specify a parameter like @first_name.  That allows ADO.NET to dynamically substitute a value for the variable @first_name at runtime.
For Oracle, you can use the : (colon) symbol to specify an ADO.NET parameter.  So if you were using Oracle as your database, you would change @first_name to :first_name.

When you are creating SqlParameter objects, you need to specify the data type, the name of the database column you want to update and the new value for the column.  Then you have to add the SqlParameter to the Parameters collection in the SqlCommand object that you are using.

I have to also create the SqlParameter objects for the other database columns last_name and email_address.

    SQLUpdate += ",last_name = @last_name ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "last_name";
    dbparam.Value = last_name;
    dbcmd.Parameters.Add(dbparam);

    SQLUpdate += ",email_address = @email ";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.String;
    dbparam.ParameterName = "email";
    dbparam.Value = email;
    dbcmd.Parameters.Add(dbparam);

So that makes a total of three SqlParameter objects that I created.  But there is one more parameter that I need.  That parameter is for the customer_id column.  The customer_id is used in the “where” clause to ensure that only the correct record is updated in the database.

 ��  SQLUpdate += " where customer_id = @customer_id";
    dbparam = dbcmd.CreateParameter();
    dbparam.DbType = System.Data.DbType.Int32;
    dbparam.ParameterName = "customer_id";
    dbparam.Value = customerid;
    dbcmd.Parameters.Add(dbparam);

Next to finish off the code for the Save button, there are four lines of code left.

    dbcmd.CommandText = SQLUpdate;
    dbcmd.Connection = dbconn;
    dbconn.Open();
    dbcmd.ExecuteNonQuery();

In those final lines of code I assign the text string for the Update to the SqlCommand object dbcmd and associate the SqlConnection object with the dbcmd.  Then notice that I explicitly open the connection.  If you remember in the prior lesson, when I was using the SqlDataAdapter class, I didn’t need to open the connection because the SqlDataAdapter does that automatically.  When you are not using the SqlDataAdapter like in this lesson, you have to explicitly open the connection because the SqlCommand object doesn’t do that automatically.  The last line of code is a call to the ExecuteNonQuery() method of the SqlCommand class.

ExecuteNonQuery() is used whenever you want to run a database operation and you are not expecting back any data.  Examples of when you can use ExecuteNonQuery are when you need to execute SQL Update, Insert or Delete operations.

That wasn’t so hard was it?

You can think of the entire development process of using parameterized ADO.NET Update operation as follows:
1) Specify your SQL Update statement and use the @ symbol where SqlParameter variables are needed.  If you are using Oracle, us the : (colon) symbol to prefix the SqlParameter variable name.
2) Create each SqlParameter object and assign it a name, a type and a value.  You can create multiple SqlParameter objects if you need more than one variable in the Update operation.
3) Associate the SqlConnection object with the SqlCommand object.
4) Open the SqlConnection object.
5) Run the ExecuteNonQuery() method of the SqlCommand object.

Take a look at this video that shows me Updating an SQL Server database record with ADO.NET in ASP.NET.

Stay tuned for the next lesson where I’m going to show you how to Insert a database record using ADO.NET with parameters in ASP.NET.

Category: ADO.NET

Click here to download the source code for this lesson.  When you open the project files, set GridView_SQLServer.aspx as the Start Page.

This lesson builds on the knowledge of a prior lesson entitled “Using the ASP.NET GridView control to query a SQL Server database with ADO.NET
In that lesson I covered the basics of ADO.NET programming with ASP.NET and C#.  Concepts such as the System.Data.SqlClient namespace, the SqlConnection class, the SqlDataAdapter class, and the DataSet class were covered.  If you haven’t read that lesson yet, it is important to do so because it is the foundation for this lesson and I don’t repeat the same material.

In this lesson, I am going to cover how to use the ADO.NET SqlCommand and SqlParameter classes (along with the SqlDataAdapter) to run an SQL query with parameters against an SQL Server database table.  This lesson applies to ASP.NET with C#.

Why would you need to use parameters with an SQL query?
Whenever you need to find an individual database record or perform a search to retrieve a group of records.  In both cases, you need a way to execute an SQL query with a “where” clause so that you can limit the data returned to specific records that you are interested in finding.  The where clause values are passed using parameters.  This lesson assumes you are searching for a specific record, but you can apply the same technique to search for multiple records.

Let me get started.  First the business requirements.  In the prior lesson “Using the ASP.NET GridView control to query a SQL Server database with ADO.NET” I had created a web form named GridView_SQLServer.aspx.  That form contains an ASP.NET GridView that displays the records in a SQL Server database table named “Customer”.

Let’s say that I have a new requirement which states I must allow Editing (or Updating) of the records in the Customer table.  One way I can achieve this is by creating an Edit page that will retrieve the data for a specific Customer record and allow modification of the fields.

I will create a new web form named Customer_Edit.aspx.  Then I will add some TextBox controls to hold the data from the Customer table and allow the user to modify the data.  I will also add a Save button that will give the user the ability to update the information back to the database table.  Here is what my Customer_Edit.aspx looks like inside the form tag:

<asp:Label ID="Label4" runat="server" 
    Text="Edit Customer Record"></asp:Label>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="First Name:">
</asp:Label>
<asp:TextBox ID="txtFirstName" runat="server" MaxLength="50">
</asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Last Name:">
</asp:Label>
<asp:TextBox ID="txtLastName" runat="server" MaxLength="50">
</asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="E-mail address:">
</asp:Label>
<asp:TextBox ID="txtEmail" runat="server" MaxLength="50">
</asp:TextBox>
<br />
<asp:Button ID="btnSave" runat="server" Text="Save" />

Now I need a way to retrieve the individual Customer record when this web form opens.  If you want to execute code when a web form opens, you place the code in the special event named Page_Load.

In order to retrieve a specific Customer record from the database, I need to use the unique identifier for a Customer which is the “customer_id” column in my Customer table.  In my application, the GridView_SQLServer.aspx page contains a hyperlink to this form Customer_Edit.aspx and it passes a variable named “customerid” by using a QueryString.  That variable’s value is dynamically taken from the “customer_id” database column.  In the browser this looks something like this:
Customer_Edit.aspx?customerid=55

Notice the QueryString variable follows the ? question mark in the URL.  I need to get the value of that variable so I place the following code in my Customer_Edit.aspx Page_Load method:

string sCustomerId = Request.QueryString["customerid"];
int customerid = int.Parse(sCustomerId);

The next step is to write code to execute a query against the database and retrieve the Customer record that I need based on the customerid variable value.  To do that I will need to use two ADO.NET database classes that were not in the prior lesson.  The first one is the SqlCommand class which allows me to use parameters for queries and the second one is the SqlParameter class which is used to hold the value of the variables used as parameters.  These two additional classes are used in conjunction with the SqlDataAdapter and DataSet.

First let me show you what the entire block of code looks like to perform a database search with ADO.NET parameters and then I will talk about each specific section separately:

SqlDataAdapter dbadapter = null;
SqlCommand dbcmd = new SqlCommand();
SqlParameter dbparam = null;
DataSet dbdata = new DataSet();

using (SqlConnection dbconn = new SqlConnection(
 "Server=localhost;"
 + "Database=csharpuniversity;"
 + "User ID=sa;"
 + "Password=Sqlserverpass$123;"
 + "Trusted_Connection=False;"))
{
 dbcmd.CommandText = "select * from customer "
 + "where customer_id = @customer_id";

 dbparam = dbcmd.CreateParameter();
 dbparam.ParameterName = "customer_id";
 dbparam.DbType = DbType.Int32;
 dbparam.Value = customerid;
 dbcmd.Parameters.Add(dbparam);

 dbcmd.Connection = dbconn;

 dbadapter = new SqlDataAdapter(dbcmd);

 dbadapter.Fill(dbdata);
}

Now, I will go into each individual section and talk about what is going on with this code.  The declaration section contains a declaration for the four variables needed in this example:

SqlDataAdapter dbadapter = null;
SqlCommand dbcmd = new SqlCommand();
SqlParameter dbparam = null;
DataSet dbdata = new DataSet();

Notice that I had to instantiate the SqlCommand object.  This is necessary in order to be able to create an SqlParameter object further down in the code.  I also had to instantiate the DataSet object which is always necessary before you try to put data into it.

Next, I created the SqlConnection object inside the “using” keyword and passed the connection string for the database.  I’m not going to go over that again since it was covered in the prior lesson.

Then, I set the value of the CommandText property for the SqlCommand object:

dbcmd.CommandText = "select * from customer "
 + "where customer_id = @customer_id";

That is where I am able to specify the SQL query to use for the search operation.  Notice that I placed a variable named @customer_id inside the query literal text.  The @ symbol is used for Sql Server parameters in Select, Update, Insert and Delete operations.  Think of the @ variable as a placeholder that will get dynamically replaced with a value at runtime.  For Oracle, you can use the : (colon) symbol to specify an ADO.NET parameter.  So if you were using Oracle as your database, you would change @customer_id to :customer_id.  Not a big difference is it?

Now I need a way to specify the value of the @customer_id variable for my search query.  in order to do that I have to create an SqlParameter object:

dbparam = dbcmd.CreateParameter();
dbparam.ParameterName = "customer_id";
dbparam.DbType = DbType.Int32;
dbparam.Value = customerid;
dbcmd.Parameters.Add(dbparam);

Notice that I had to create the SqlParameter object by using a method in the SqlCommand class named CreateParameter().  I also had to specify the name of the parameter which must match exactly with what I put in my query text (customer_id).  I need to specify the type of the variable which is in Integer and assign a value to the parameter.  Notice that I assigned the value of the variable customerid which came from the QueryString.  I also need to add the parameter to the SqlCommand Parameters collection by using the Add() method.

After setting up the SqlParameter object, all I have to do is assign an SqlConnection object to the SqlCommand and then pass the SqlCommand to the SqlDataAdapter object which executes the query by using the Fill() method.

dbcmd.Connection = dbconn;

dbadapter = new SqlDataAdapter(dbcmd);

dbadapter.Fill(dbdata);

Not so bad is it?  You can think of the entire development process of using parameterized ADO.NET queries as follows:
1) Specify your SQL Select query statement and use the @ symbol where SqlParameter variables are needed.  If you are using Oracle, us the : (colon) symbol to prefix the SqlParameter variable name.
2) Create the SqlParameter object and assign it a name, a type and a value.  You can create multiple SqlParameter objects if you need more than one variable in the “where” clause.
3) Associate the SqlConnection object with the SqlCommand object and then pass the SqlCommand object to the SqlDataAdapter constructor.

One final thing that I am going to do is to take the data from the DataSet object and populate the TextBox controls on the web form with the associated data values from the database.

if (dbdata.Tables[0].Rows.Count > 0)
{
 txtFirstName.Text =
     dbdata.Tables[0].Rows[0]["first_name"].ToString();
 txtLastName.Text =
     dbdata.Tables[0].Rows[0]["last_name"].ToString();
 txtEmail.Text =
     dbdata.Tables[0].Rows[0]["email_address"].ToString();
}

Notice that I’m checking to see if any data was found that matches my query by using an “if” statement and checking the Rows collection of the DataTable object that is inside the DataSet.  To retrieve the data value for each TextBox control, I also have to reference the Rows collection.  Since there should be only one row returned because this is an exact match search based on a unique identifier column, I check the row number zero 0: Rows[0].  In order to reference a specific column in a DataSet object with only a single row you can use the following convention:
dbdata.Tables[0].Rows[0][”NAME OF COLUMN”]
And replace NAME OF COLUMN with your database table’s column name.  You also should replace the name of the DataSet variable dbdata and replace with your variable name.

Take a look at this video that shows me executing dynamic ADO.NET queries using parameters.

Stay tuned for the next lesson where I’m going to show you how to give the user the ability to Update the data back to the database.

Category: News

Last week, my article “Uploading files and validating them using the ASP.NET FileUpload and CustomValidator controls” was chosen by Microsoft as an Article of the Day on (The Official Microsoft ASP.NET Site).  This is an honor for me as a programmer and I’m grateful to all of you subscribers and supporters of the website.

I want to take a quick second and thank YOU for subscribing and for all your comments!  You really do help me make csharpuniversity.com the best website for amazing asp.net.  Over the next few weeks I will be posting lots of new articles and making additional improvements to the website so I look forward to hearing from you as you continue to learn more and enjoy reading what I have to say.