[fname]
,[lname]
,[userid]
,[username]
,[password]
,[confirmpassword]
,[gender]
,[location]
,[language]**i have used listbox for language..if i select multiple languages they should b stored in DB in the field of language..
,[mobileno]
,[mailid]
,[address]
,[image]
FROM [sailam].[dbo].[register..this is my table fields...
My code is:
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;
using System.IO;
using System.Drawing;
public partial class registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int cnt = 0;
SqlConnection con = new SqlConnection("Data source=RAJA-PC;Initial Catalog=sailam;User id=sa;Password=sa123");
//string s = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
//SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into register values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + RadioButtonList1.SelectedItem.Text + "','" + DropDownList1.SelectedItem.Text + "','" + ListBox1.SelectedItem.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + FileUpload1.PostedFile.FileName + "')",con);
cmd.ExecuteNonQuery();
i hav used this code but displaying multiple items of only language field..other fields values are showing null..
//string lang = "insert into register(language)values(@language)";
//string connstring = "Data source=RAJA-PC;Initial Catalog=sailam;User id=sa;Password=sa123";
////SqlCommand cmd1=new SqlCommand(lang,con);
//cmd.Parameters.Add("@language", SqlDbType.VarChar, 100);
//foreach (ListItem item in ListBox1.Items)
//{
// if (item.Selected)
// {
// try
// {
// cmd.Parameters["@language"].Value = item.Text;
// cmd.ExecuteNonQuery();
// Label17.ForeColor = Color.Green;
// Label17.Text = "Data Inserted";
// }
// catch (Exception ex)
// {
// Label17.Text = ex.Message;
// }
// }
//}
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("images/" + filename));
con.Close();
if (cnt == 0)
{
Label15.Text = "values are inserted successfully";
}
else
{
Label15.Text = "plz enter";
}
clear();
}
public void clear()
{
foreach (Control c1 in form1.Controls)
{
if (c1 is TextBox)
{
((TextBox)c1).Text = "";
}
if (c1 is DropDownList)
{
((DropDownList)c1).SelectedIndex = -1;
}
}
}
}