Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:42:13+00:00 2026-06-16T07:42:13+00:00

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

  • 0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ADO_DataSet_Prac
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataSet ds = new DataSet();
        SqlDataAdapter da;
        DataTable dt;

        private void Form1_Load(object sender, EventArgs e)
        { 
            SqlConnection con = new SqlConnection("Server = localhost; Database = MSNETDB; Integrated Security=True;MultipleActiveResultSets=True");
             da = new SqlDataAdapter("Select * from Emp",con);
             da.Fill(ds, "Emp");
             dt=ds.Tables["Emp"];
             gvEmp.DataSource = dt;

           //Insert command for data adapter
            SqlCommand cmdInsert = new SqlCommand("Insert into Emp(EmpName,EmpSalary) Values(@Name,@Salary)", con);
            SqlParameter Name = cmdInsert.Parameters.Add("@Name", SqlDbType.VarChar, 100);
            SqlParameter Salary = cmdInsert.Parameters.Add("@Salary", SqlDbType.Money);
            Name.SourceColumn = "EmpName";
            Salary.SourceColumn = "EmpSalary";
            da.InsertCommand = cmdInsert;

            //Update command for data adapter
            SqlCommand cmdUpdate = new SqlCommand("Update Emp set EmpName =@Name, EmpSalary =@Salary where EmpId=@Id", con);
            SqlParameter Id = cmdUpdate.Parameters.Add("@Id", SqlDbType.Int);
            Name.SourceColumn = "EmpName";
            Salary.SourceColumn = "EmpSalary";
            Id.SourceColumn = "EmpId";
            da.UpdateCommand = cmdUpdate;
}
 private void btnDa_Update_Click(object sender, EventArgs e)
        {
            da.Update(ds,"Emp"); //Exception throw here
        }
    }
}

While trying to update, I get a SqlException saying:

Must declare the scalar variable “@Name”.

The exception is thrown on

da.update(ds,"Emp") 

method of data adapter. I don’t know what is the reason. I checked all my syntax and errors and everything looks fine but still it is throwing error. I tried with break point as well but with no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:42:14+00:00Added an answer on June 16, 2026 at 7:42 am

    You have declared parameters @Name and @Salary for insert command by

    cmdInsert.Parameters.Add("@Name"...
    

    But later you are trying to use them for updtae command. Just add new parameters for update as well, for example like this:

    SqlParameter NameUpdate = cmdUpdate.Parameters.Add("@Name", SqlDbType.VarChar, 100);
    SqlParameter SalaryUpdate = cmdUpdate.Parameters.Add("@Salary", SqlDbType.Money);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.