473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to update all rows using text box

I retrieve all the row values from database into text box.But I could not Update it.It shows error message is
The variable name '@value' has already been declared. Variable names must be unique within a query batch or stored procedure.
Must declare the scalar variable "@keyValue".

my code is here:

Expand|Select|Wrap|Line Numbers
  1. public partial class ECB_ECBConfiguration : System.Web.UI.Page
  2. {
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         DataTable dt = ECBDal.GetECBConfiguration();
  6.        foreach(DataColumn col in dt.Columns) 
  7.         {
  8.  
  9.             if (dt.Rows.Count > 0)
  10.             {
  11.                 txtECBAddress.Text = dt.Rows[0]["Value"].ToString().Trim();
  12.                 txtECBServer.Text = dt.Rows[1]["Value"].ToString();
  13.                 txtECBEMailID.Text = dt.Rows[2]["Value"].ToString();
  14.                 txtECBContactNo1.Text = dt.Rows[3]["Value"].ToString();
  15.                 txtECBContactNo2.Text = dt.Rows[4]["Value"].ToString();
  16.                 txtECBContactNo3.Text = dt.Rows[5]["Value"].ToString();
  17.                 txtECBContactNo4.Text = dt.Rows[6]["Value"].ToString();
  18.                 txtECBContactNo5.Text = dt.Rows[7]["Value"].ToString();
  19.             }
  20.         }
  21.     }
  22.     protected void btnSave_Click(object sender, EventArgs e)
  23.     {
  24.         using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["MSSQLConnectionString"]))
  25.         {
  26.             SqlCommand cmd = new SqlCommand("UPDATE ECB_Configuration SET [Value] = @value where [Key] = @keyValue", con);
  27.             con.Open();
  28.  
  29.             cmd.Parameters.AddWithValue("@value", txtECBAddress.Text);
  30.             cmd.Parameters.AddWithValue("@value", txtECBServer.Text);
  31.             cmd.Parameters.AddWithValue("@value", txtECBEMailID.Text);
  32.             cmd.Parameters.AddWithValue("@value", txtECBContactNo1.Text);
  33.             cmd.Parameters.AddWithValue("@value", txtECBContactNo2.Text);
  34.             cmd.Parameters.AddWithValue("@value", txtECBContactNo3.Text);
  35.             cmd.Parameters.AddWithValue("@value", txtECBContactNo4.Text);
  36.             cmd.Parameters.AddWithValue("@value", txtECBContactNo5.Text);
  37.             cmd.ExecuteNonQuery();
  38.             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Updated Successfully')", true);
  39.             con.Close();
  40.         }
  41.  
  42.     }
  43.     //protected void btnSave_Click(object sender, EventArgs e)
  44.     //{
  45.     //    ECBDal.SaveECBConfiguration();
  46.  
  47.     //}
  48.  
  49.  
  50. }
Sep 12 '14 #1
1 1319
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

You defined value a bunch of times. And you never define the keyValue variable that you reference in your SQL.
Sep 12 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: N. Graves | last post by:
I guess I'm the last one to know but I will ask anyway. I need to have the ability on a form to update a bound text box ( txtTotalSalesprice) to a field TotalSalesprice and it needs to match...
4
by: gj | last post by:
Hi, I'm trying to update a sql database from a web form using text boxes. I'm trying to learn C# on my own so I am at a complete loss. I created my sql connection, data adapter, dataset and data...
0
by: ksrajalakshmi | last post by:
Hai, I've displayed all data in a datagrid. the datasource is a dataset. the user can modify the data in the datagrid. the updated data in the datagrid to be updated in datatable. i used the...
0
by: neo | last post by:
I am working on vs2k5. I made MFC-SDI application and view class inherited from CListView. I was tried a lot to bold one row in List using custom drawing but I was able not understand, how to use...
0
by: Eric Effer | last post by:
Hi I am a asp.net 2.0 newbie and I was thinking how to update rows in a dataset? How to find rows and update these rows manually? thanks E
6
by: kareemaffan | last post by:
Hello Everyone I want to insert values into MS Access database through VB.NET in Visual Studio 2005 . I have used the following code which is not working. Private Sub Button2_Click(ByVal sender...
4
by: Matteo Migliore | last post by:
Hi. I writed a method that takes two DataTable with same schema and return a third DataTable that: - insert new rows from "compare" DataTable - delete rows contained in "source" and not in...
2
by: Claudia Fong | last post by:
Hi, How can I create a grid of 20 Columns by 30 Rows using asp.net? Cheers! Claudi *** Sent via Developersdex http://www.developersdex.com ***
1
by: tembil | last post by:
Hi, I'm designing a windows application in visual studio 2008 and connecting to oracle 10g XE but don't know how to add, update and delete records from my database using text boxes. Thanks in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.