473,246 Members | 1,932 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,246 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 2766
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
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.