Ive made a asp.net webform containing some listboxes,textboxes, dropdown lists etc. The selection mode for list box is multiple. When I run my code and enter the values in the various boxes and click the go button, the same page is returned with selected items and the data doesn't go into the database.
What to do....Plz help :(
The code is:
private void Postjob(string username,string companyname,string locations,string experiencemin,string experiencemax,string keyskills, string funcArea,string Industry, string postdate, string about, string desc)
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Project3\\App_Data\\ojb1.mdf;Integrated Security=True;User Instance=True");
String sql = "INSERT INTO db(username,Companyname,Locations,Experiencemin,Experiencemax,Keyskills,Functionarea,Industry,Posted_date,About_Company,Job_Description)" +"VALUES(@userName,@Companyname,@Locations,@Experiencemin,@Experiencemax,@Keyskills,@Functionarea,@Industry,@Posted_date,@About_Company,@Job_Description)";
try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlParameter[] param = new SqlParameter[11];
param[0] = new SqlParameter("@userName", SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@Companyname", SqlDbType.VarChar, 50);
param[2] = new SqlParameter("@Locations", SqlDbType.VarChar, 100);
param[3] = new SqlParameter("@Experiencemin", SqlDbType.VarChar, 50);
param[4] = new SqlParameter("@Experiencemax", SqlDbType.VarChar, 50);
param[5] = new SqlParameter("@Keyskills", SqlDbType.VarChar, 1000);
param[6] = new SqlParameter("@Functionarea", SqlDbType.VarChar, 50);
param[7] = new SqlParameter("@Industry", SqlDbType.VarChar, 50);
param[8] = new SqlParameter("@Posted_date", SqlDbType.VarChar, 50);
param[9] = new SqlParameter("@About_Company", SqlDbType.VarChar, 1000);
param[10] = new SqlParameter("@Job_Description", SqlDbType.VarChar, 1000);
param[0].Value = username;
param[1].Value = companyname;
param[2].Value = locations;
param[3].Value = experiencemin;
param[4].Value = experiencemax;
param[5].Value = keyskills;
param[6].Value = funcArea;
param[7].Value = Industry;
param[8].Value = postdate;
param[9].Value = about;
param[10].Value = desc;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string msg = "Insert Error";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
protected void Submit_Click(object sender, EventArgs e)
{
if (CompanyName.Text != "" && ListBoxLoc.SelectedItem.Text != "" && Expmin.Text != "" && Expmax.Text != "" && Keyskill.Text != "" && ListBoxFun.SelectedItem.Text != "" && ListBoxInd.SelectedItem.Text != "" && abtcomp.Text != "" && JobDesc.Text != "")
{
Postjob(username.Text, CompanyName.Text, ListBoxLoc.SelectedItem.Text, Expmin.Text, Expmax.Text, Keyskill.Text, ListBoxFun.SelectedItem.Text, ListBoxInd.SelectedItem.Text, postdate.Text, abtcomp.Text, JobDesc.Text);
Response.Redirect("Home.aspx");
}