Advertisement

11.04.2007 at 11:28AM PST, ID: 22937872
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

Beginner's question: Using Parameters on SqlCommand

Asked by josgood in C# Programming Language, .NET

Tags: ,

Im teaching myself how to use a strongly typed dataset in C#.  I want to do this by hand, rather than letting a wizard build it all for me  you dont know something if you dont know how to do it by hand.

The code below has two problems, which probably have the same cause:
1)  After building the other commands via SqlCommandBuilder, the SqlDataAdapter shows null Insert, Delete, and Update. commands.
2)  When the code executes da.Fill(ds), I get an exception saying

The parameterized query '(@Col1 int,@Col2 int)Select @Col1, @Col2 from TestTable' expects the parameter '@Col1', which was not supplied.

What am I doing wrong?

using System;
using System.Data;
using System.Data.SqlClient;

namespace QuickSQL {
   class Program {
      static void Main(string[] args) {
         SqlConnection conn = new SqlConnection(@"Server=(local)\SQLEXPRESS;Initial Catalog=;Integrated Security=SSPI");
         conn.Open();
         SqlCommand cmd0 = new SqlCommand("Use Test",conn);
         cmd0.ExecuteNonQuery();
         SqlCommand cmd1 = new SqlCommand("Create Table TestTable (Col1 Int Primary Key, Col2 Int)",conn);
         cmd1.ExecuteNonQuery();
         
         SqlDataAdapter da = new SqlDataAdapter("Select @Col1, @Col2 from TestTable",conn);
         da.SelectCommand.Parameters.Add("@Col1", SqlDbType.Int);
         da.SelectCommand.Parameters.Add("@Col2", SqlDbType.Int);
         SqlCommandBuilder builderTarget = new SqlCommandBuilder(da);
         
         DataSet ds = new DataSet();
         ds.Clear(); da.Fill(ds); // Exception thrown on da.Fill(ds)
         conn.Close();
      }
   }
}

Start Free Trial
[+][-]11.04.2007 at 11:34AM PST, ID: 20211764

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 11:40AM PST, ID: 20211792

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 11:58AM PST, ID: 20211864

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 12:07PM PST, ID: 20211898

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 12:12PM PST, ID: 20211918

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, .NET
Tags: parameters, sqlcommand
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.04.2007 at 12:19PM PST, ID: 20211944

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 01:29PM PST, ID: 20212321

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.04.2007 at 01:36PM PST, ID: 20212388

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.06.2007 at 07:08AM PST, ID: 20224434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.06.2007 at 07:29AM PST, ID: 20224628

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906