I am usng VS 2010 and I have a Website I am building using C#.
My goal is when a user selects a value from the dropdownlist it is recorded in the database.
I have been able to bind the DDL to a table called "TableA" to list the values needed sucessfully.
But, I want the values to be recorded in a table called "tbl_Main"
The DDL ID on the the aspx page is "ut_1" and the column name in the table that I want the data recorded to is called "ut_1" aswell.
No errors show when debugging but the values never update.
Any help would be greatly appreciated. :)
Here is my BehindCode so far.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace techtrax
{
public partial class Default : System.Web.UI.Page
{
protected void ddl_ut1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["techtraxConnectionString"].ConnectionString);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand("Update tbl_main SET ut_1=@ut_1 where JSN=@JSN", sqlConn);
DropDownList ddl = (DropDownList)sender;
sqlCmd.Parameters.Add("@ut_1", System.Data.SqlDbType.NVarChar, 50);
sqlCmd.Parameters["@ut_1"]. = ddl.SelectedItem.Value;
sqlConn.Close();
}
}
}