473,378 Members | 1,500 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,378 software developers and data experts.

System.Data.SqlClient.SqlException

3
Please help me

" System.Data.SqlClient.SqlException: Prepared statement '(@Name varchar(100),@Describes varchar(100),@Money char(10))Upda' expects parameter @Describes, which was not supplied. at System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Assignment.rose.dtgFlower_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\assignment1\rose.ascx.cs:line 111Error:Cannot update "

This is the code
Expand|Select|Wrap|Line Numbers
  1. "namespace Assignment
  2. {
  3.     using System;
  4.     using System.Data;
  5.     using System.Drawing;
  6.     using System.Web;
  7.     using System.Web.UI.WebControls;
  8.     using System.Web.UI.HtmlControls;
  9.     using System.Data.SqlClient;
  10.  
  11.     /// <summary>
  12.     ///        Summary description for rose.
  13.     /// </summary>
  14.     public class rose : System.Web.UI.UserControl
  15.     {
  16.         protected System.Web.UI.WebControls.DataGrid dtgFlower;
  17.  
  18.         private void Page_Load(object sender, System.EventArgs e)
  19.         {
  20.             // Put user code to initialize the page here
  21.             SqlConnection sqlcon=new SqlConnection("server=(local);uid=sa;pwd=12345;database=Assignment");
  22.             SqlCommand sqlcom=new SqlCommand("select * from ProductFlower",sqlcon);
  23.             sqlcon.Open();
  24.             SqlDataReader sqlreader;
  25.             sqlreader=sqlcom.ExecuteReader();
  26.             if(sqlreader.HasRows)
  27.             {
  28.                 dtgFlower.DataSource=sqlreader;
  29.                 dtgFlower.DataBind();
  30.             }
  31.             else
  32.             {
  33.                 sqlcon.Close();
  34.             }
  35.             if(!IsPostBack)
  36.                  BindGrid();
  37.         }
  38.  
  39.         #region Web Form Designer generated code
  40.         override protected void OnInit(EventArgs e)
  41.         {
  42.             //
  43.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  44.             //
  45.             InitializeComponent();
  46.             base.OnInit(e);
  47.         }
  48.  
  49.         /// <summary>
  50.         ///        Required method for Designer support - do not modify
  51.         ///        the contents of this method with the code editor.
  52.         /// </summary>
  53.         private void InitializeComponent()
  54.         {
  55.             this.dtgFlower.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtgFlower_CancelCommand);
  56.             this.dtgFlower.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtgFlower_EditCommand);
  57.             this.dtgFlower.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtgFlower_UpdateCommand);
  58.             this.dtgFlower.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtgFlower_DeleteCommand);
  59.             this.Load += new System.EventHandler(this.Page_Load);
  60.  
  61.         }
  62.         #endregion
  63.  
  64.         protected System.Web.UI.WebControls.Label lblMessage;
  65.  
  66.  
  67.         SqlConnection sqlcon=new SqlConnection("server=(local);uid=sa;pwd=12345;database=Assignment");
  68.  
  69.         public void BindGrid()
  70.         {
  71.             SqlDataAdapter sqlda=new SqlDataAdapter("select * from ProductFlower",sqlcon);
  72.             DataSet ds=new DataSet();
  73.             sqlda.Fill(ds,"ProductFlower");
  74.             dtgFlower.DataSource=ds.Tables["ProductFlower"].DefaultView;
  75.             dtgFlower.DataBind();
  76.         }
  77.  
  78.         private void dtgFlower_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  79.         {
  80.             dtgFlower.Columns[0].HeaderText="Cancel";
  81.             dtgFlower.EditItemIndex=-1;
  82.             BindGrid();
  83.         }
  84.  
  85.         //private TextBox txtDescribes,txtMoney;
  86.  
  87.         private void dtgFlower_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  88.         {
  89.  
  90.             dtgFlower.Columns[5].HeaderText="Update";
  91.             int ID = Int32.Parse(dtgFlower.DataKeys[e.Item.ItemIndex].ToString());    
  92.             string strUpdate="Update ProductFlower set Name=@Name,Describes=@Describes,Money=@Money where ProductID=ID";
  93.             SqlCommand sqlcom=new SqlCommand(strUpdate,sqlcon);
  94.  
  95.             //sqlcom.Parameters.Add(new SqlParameter("@ProductID",SqlDbType.Int,4));
  96.             //sqlcom.Parameters.Add(new SqlParameter("@Image",SqlDbType.VarChar,100));
  97.             sqlcom.Parameters.Add(new SqlParameter("@Name",SqlDbType.VarChar,100));
  98.             sqlcom.Parameters.Add(new SqlParameter("@Describes",SqlDbType.VarChar,100));
  99.             sqlcom.Parameters.Add(new SqlParameter("@Money",SqlDbType.Char,10));
  100.  
  101.             //sqlcom.Parameters["@ProductID"].Value=dtgFlower.DataKeys[(int)e.Item.ItemIndex];
  102.             //sqlcom.Parameters["@Image"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
  103.             sqlcom.Parameters["@Name"].Value=((TextBox)e.Item.Cells[3].Controls[0]).Text;
  104.             sqlcom.Parameters["@Describes"].Value=(e.Item.FindControl("TextBox"));
  105.             sqlcom.Parameters["@Money"].Value=(e.Item.FindControl("TextBox"));
  106.             //sqlcom.Parameters["@Describes"].Value=((TextBox)e.Item.Cells[4].Controls[0]).Text;
  107.             //sqlcom.Parameters["@Money"].Value=((TextBox)e.Item.Cells[5].Controls[0]).Text;
  108.             sqlcon.Open();
  109.             try
  110.             {
  111.                 sqlcom.ExecuteNonQuery();
  112.                 lblMessage.Text="Completed Successful";
  113.                 dtgFlower.EditItemIndex=-1;
  114.             }
  115.             catch(SqlException exc)
  116.             {
  117.                 if(exc.Number==2627)
  118.                     lblMessage.Text="Error";
  119.                 else
  120.                     lblMessage.Text=exc.ToString()+"Error:Cannot update";
  121.             }
  122.             sqlcon.Close();
  123.             BindGrid();
  124.         }
  125.  
  126.         private void dtgFlower_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  127.         {
  128.             dtgFlower.Columns[5].HeaderText="Edit";
  129.             dtgFlower.EditItemIndex=(int)e.Item.ItemIndex;
  130.             BindGrid();
  131.         }
  132.  
  133.         private void dtgFlower_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  134.         {
  135.             dtgFlower.Columns[6].HeaderText="Delete";
  136.             string strDelete="Delete from ProductFlower where ProductID=@ProductID";
  137.             SqlCommand sqlcom=new SqlCommand(strDelete,sqlcon);
  138.             sqlcom.Parameters.Add(new SqlParameter("@ProductID",SqlDbType.Int,4));
  139.             sqlcom.Parameters["@ProductID"].Value=dtgFlower.DataKeys[(int)e.Item.ItemIndex];
  140.             sqlcon.Open();
  141.             try
  142.             {
  143.                 sqlcom.ExecuteNonQuery();
  144.                 lblMessage.Text="Completed Successful";
  145.             }
  146.             catch(SqlException)
  147.             {
  148.                 lblMessage.Text="Error:Cannot delete";
  149.             }
  150.             sqlcon.Close();
  151.             BindGrid();
  152.         }
  153.  
  154.  
  155.  
  156.     }
  157. }
  158.  
  159.  
This is the database
"CREATE TABLE [dbo].[ProductFlower] (
[ProductID] [int] IDENTITY (1, 1) NOT NULL ,
[Image] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Describes] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Money] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY] "
Dec 15 '07 #1
1 2773
jhardman
3,406 Expert 2GB
This isn't written in VBScript. What language and what version of ASP are you using?

My first response would be to stop using complex SQL, and just dump the data you want to manipulate into a recordSet, then manipulate it how you want then update the db from the recordset. Of course, this may not be doable with all versions of ASP, so my first question is of utmost importance.

Jared
Dec 17 '07 #2

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

Similar topics

0
by: dinesh | last post by:
I'm trying to run the ibuyspy ecommerce example (www.ibuyspy.com) using MSDE as a database. I get the following error System.Data.SqlClient.SqlException: SQL Server does not exist or access denied...
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
0
by: Ersin Gençtürk | last post by:
we are getting : System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period...
1
by: HK | last post by:
I just moved an ASP.NET application to a new web server at a different location of ours. The SQL Server machine was moved to that new location at the same time as the web site DNS was pointed to...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
3
by: Rampa | last post by:
hello! the problem is always the same but i can't understand why it happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH ERROR why? Dim connessione As New...
3
by: weird0 | last post by:
This is the exception that I get when i create a webserivce obj and call. The error comes on the webmethod call, when it opens a connection to the db. How do I fix it? What is the solution to...
2
by: Carol | last post by:
Exception may be thrown in the code inside the try block. I want to handling the SqlException with State == 1 in a special way, and for all others I want to use a general way to handle. Which of...
2
by: lily86 | last post by:
i'm very new so i hope all of u can help me. when i debug my webforms this error occur "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.