Click button not working when trying to push data from Visual Studio 2008 to SQL Server.

Joe Brown
Joe Brown used Ask the Experts™
on
This is the code I have written in my .aspx.cs page in Visual Studio.
I do not get an error, however, the data entered in to the fields during Visual Studio are not writing back to the SQL Database. Am  I missing a piece of the code?

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class quality_CustomerComplaint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CreateCC_Click(object sender, EventArgs e)
    {
        try
        {
            string connString = ConfigurationManager.ConnectionStrings["FloratoryConnectionString"].ConnectionString;
            sqlConnection = new SqlConnection(connString);
            sqlConnection.Open();

            commitTime = DateTime.Now;
            string dateString = commitTime.ToShortDateString();

            string commandString = "INSERT INTO Out_CustomerComplaint (Out_CC_Date, Out_CC_Customer, " +
                                   "Out_CC_Contact, Out_CC_Problem, Out_CC_Employee, Out_CC_PO, Out_CC_NCNumber, " +
                                   "Out_CC_CARNumber, OUT_CC_RGANumber) VALUES (" +
                                   "'" + commitTime.ToShortDateString() + "', " + // Date
                                   "'" + Customer.Text + "', " +
                                   "'" + Contact.Text + "', " +
                                   "'" + Problem.Text + "', " +
                                   "'User', ";          

                                   commandString += ")";

 
           

            SqlCommand command = new SqlCommand(commandString, sqlConnection);
            int num_changed = command.ExecuteNonQuery();
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.ToString());
        }
       
    }
   
    protected DateTime commitTime;
    protected SqlConnection sqlConnection;
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try changing this line

protected void CreateCC_Click(object sender, EventArgs e)

to

protected void CreateCC_Click(object sender, EventArgs e) handles CreateCC.Click

Commented:
sorry i didn't read your code properly. It seems asp.net application in c#.
check in your aspx page button definition has the clickevent handler specified or not as follows

<asp:Button ID="CreateCC" runat="server" OnClick="CreateCC_Click" Style="z-index: 100;
            left: 0px; position: absolute; top: 0px" Text="Button" />
what previous post was trying to say in a curious mix of VB.NET and C# is "check if you set the OnClick event handler" for your button ;)

if you don't see the code executed it most probably means that the handler isn't set

Commented:
alexey_gusev: i realized it after posting ;)
yeah, I see now :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial