error insert into

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zizi2
    New Member
    • Apr 2009
    • 17

    #16
    Sorry to be a pain, I've checked and I have @Expiry_date and @Email_address, I can't find the spelling mistakes in the new version of my code, please help.

    Comment

    • dbdb
      New Member
      • Feb 2009
      • 25

      #17
      i don't know it could be run well or not. why don't you try just like i did.

      i add the braket among the date field. like this :

      Code:
      insert into Intranet.classifieds_adverts (Title, [Expiry_date], Description, Added_by, Email_address) 
      values (@Title, @Expiry_date, @Description, @Added_by, @Email_address)
      wish it could be help.
      coz my problem solve by that.

      Comment

      • Hamayun Khan
        New Member
        • Aug 2007
        • 106

        #18
        Originally posted by zizi2
        thanks maliksleo, i have correct the typo and it now looks like(below) this but I'm still getting the error, not sure what am I doing wrong.


        Code:
        private void Submit_Click(object sender, System.EventArgs e)
        		{
        		SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        		SqlCommand cmd =  new SqlCommand("Add_advert", con);
                cmd.CommandType = CommandType.StoredProcedure;
        		con.Open();
        		cmd.Parameters.Add("@Title",SqlDbType.VarChar);
        		cmd.Parameters["@Title"].Value = txtTitle;
        		cmd.Parameters.Add("@Expiry_date",SqlDbType.DateTime);
        		cmd.Parameters["@Expiry_date"].Value = txtExpiryDATE;
        		cmd.Parameters.Add("@Description",SqlDbType.Text );
        		cmd.Parameters["@Description"].Value = txtDescr;
        		cmd.Parameters.Add("@Added_by",SqlDbType.VarChar );
        		cmd.Parameters["@Added_by"].Value = txtName;
        		cmd.Parameters.Add("@Email_address",SqlDbType.VarChar );
        		cmd.Parameters["@Email_address"].Value = txtEmail;
        				
        		
                cmd.ExecuteNonQuery();
        		con.Close();
        		
              
        		}
        if txtTitle, txtDescr,txtNam e,txtEmail are text fields then use like
        Code:
        cmd.Parameters["@Email_address"].Value = txtEmail.Text;

        Comment

        • zizi2
          New Member
          • Apr 2009
          • 17

          #19
          Thanks hammayun, it worked I needed to added the ".txt" and DateTime.Parse for the ExpiryDATE.

          Thanks everyone for all your help.

          Comment

          Working...