Click here to Skip to main content
12,250,546 members (49,841 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server SQL-Server-2008 , +
[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;
}
}
}
}
Posted 13-Nov-12 18:02pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you select all a database value (language field) in datatable and this datatable bind with dropdown box those select a language.
  Permalink  
Comments
sailam52 15-Nov-12 22:05pm
   
hai rohit...thank u for ur solution..can u please post me the code for selecting multiple items from listbox to database..plzz post me t code..i wl b much thankful to u..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100