C# .NET - how to search related string datas in compobox

Asked By Chinnarasu Chinnarasu.M
03-Feb-12 02:42 AM
hai, i use c# windows applications , i load number of names set in compobox i need to search particular name and show related names show to compobox how to use it please help me......
  Reena Jain replied to Chinnarasu Chinnarasu.M
03-Feb-12 02:52 AM
hi,

 ust use the below query to get the data

select id, Name from table1 where name like '% reena %'

This will fetch only those rows which is having name reena.

Hope this will help you
  Chinnarasu Chinnarasu.M replied to Reena Jain
03-Feb-12 03:08 AM
hai sir i use this code to bind in combobox its working well, But that combobox (raj,ragu,ram,hari,kumar,kumaran,) search weaver name ( r....) related names show .....

        conn.Open();
        cmd = new SqlCommand("select * from Master_weaver", conn);
        da = new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds, "Master_weaver");
        com_weavername.Items.Clear();
        com_weavername.Items.Add("All");
        for (int i1 = 0; i1 < ds.Tables[0].Rows.Count; i1++)
        {
          DataRow dr = ds.Tables[0].Rows[i1];
          com_weavername.Items.Add(dr["WeaverName"].ToString());
        }
  dipa ahuja replied to Chinnarasu Chinnarasu.M
03-Feb-12 03:31 AM
Try this :
string conn = "ConnectionString";
  
private void listFilter_Load(object sender, EventArgs e)
{
  SqlDataAdapter da = new SqlDataAdapter("select full_name from tb1", conn);
  DataTable dt = new DataTable();
  da.Fill(dt);
 
  comboBox1.DataSource = dt;
  comboBox1.DisplayMember = "full_name";
}
  
private void textBox1_TextChanged(object sender, EventArgs e)
{
  SqlDataAdapter da = new SqlDataAdapter("select full_name from tb1 where full_name like '%" 
  + textBox1.Text + "%'", conn);
 
  DataTable dt = new DataTable();
  da.Fill(dt);
 
  comboBox1.DataSource = dt;
  comboBox1.DisplayMember = "full_name";
}

            
            
            


Search By firstname

  kalpana aparnathi replied to Chinnarasu Chinnarasu.M
03-Feb-12 05:24 AM
hi,

Here give you one attachment for serching related string datas in combobox

SearchAsYouType.zip
  Reena Jain replied to Chinnarasu Chinnarasu.M
03-Feb-12 07:17 AM
Hi,

OK, why are you binding the row by row just assign datasource of combobox like this

conn.Open();
    cmd = new SqlCommand("select * from Master_weaver", conn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds, "Master_weaver");
    com_weavername.Items.Clear();
    com_weavername.DataSource=ds;

try this and let me know
Create New Account
help
with store procedure. Thanks You can use DataAdapter with stored procedure with the help of Sqlcommand object: protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { string connString = "ConnectionString" ; SqlConnection conn = new SqlConnection (connString); SqlCommand comm = new SqlCommand ( "selection" , conn); comm.CommandType = CommandType .StoredProcedure; SqlDataAdapter da = new SqlDataAdapter (comm); DataTable dt = new DataTable (); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } HI refer this protected DataTable RetrieveEmployeeSubInfo ( string employeeNo ) { SqlCommand cmd = new SqlCommand (); SqlDataAdapter da = new SqlDataAdapter (); DataTable dt = new DataTable (); try { cmd = new SqlCommand ( "RETRIEVE_EMPLOYEE" , pl . ConnOpen
SqlDataAdapter and SqlCommand private void BtnUpdate_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connectionString); string query = "update emp set name = '" + TxtName.Text + "' where id = " + TxtID.Text + ""; SqlCommand cmd = new SqlCommand(query, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); if( CONDITION ) MessageBox.Show("Value Updated successfully if true than only update else not update as follows private void BtnUpdate_Click(object sender, EventArgs e) { if( CONDITION ) { SqlConnection con = new SqlConnection(connectionString); string query = "update emp set name = '" + TxtName
content and other doesnt show string str = ConfigurationManager .AppSettings[ "connectstr" ]; protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { LoadTable(); } } public void LoadTable() { SqlConnection objconnection = new SqlConnection (str); objconnection.Open(); SqlCommand objcommand = new SqlCommand (); objcommand.CommandText = "Select * from TTable" ; objcommand.Connection = objconnection; SqlDataAdapter objAdap = new SqlDataAdapter (objcommand); DataSet ds1 = new DataSet (); objAdap.Fill(ds1); DropDownList1.DataSource = ds1.Tables[0]; DropDownList1.DataTextField TTableNo" ; DropDownList1.DataValueField = "TableID" ; DropDownList1.DataBind(); objconnection.Close(); } protected void DropDownList2_SelectedIndexChanged( object sender, EventArgs e) { LoadWaiter(); } public void LoadWaiter() { SqlConnection objconnection = new SqlConnection (str); objconnection.Open(); SqlCommand objcommand = new SqlCommand (); objcommand.CommandText = "Select * from Waiter" ; objcommand.Connection = objconnection; SqlDataAdapter objAdap = new SqlDataAdapter (objcommand); DataSet ds21
5) public partial class page3_gview : System.Web.UI.Page { allfunct objgrid = new allfunct(); DataSet ds; SqlCommand objc; SqlDataAdapter objad = new SqlDataAdapter(); protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); SqlCommand objc = new SqlCommand(); string query = "select * from tb_project"; / / string query1 = "update tb_project set proj_name = @proj_name where (sno = @sno SelectCommand = objc; objad.Fill(ds); gd1.DataSource = ds; gd1.DataBind(); } protected void edit_tab(object s, EventArgs e) { DataSet ds = new DataSet(); SqlCommand objc = new SqlCommand(); string query1 = "update tb_project set proj_name = @proj_name where (sno = @sno)"; objc.Connection
Error : CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments Can anyone help me. . . . My code : void BindGrid() { Dataset ds = new Dataset (); SqlCommand cmd = new SqlCommand (); SqlConnection conn = new SqlConnection (); DataGrid grdsrch = new DataGrid (); try { cmd.CommandText = "MKDB_connstring" ; cmd.CommandType = CommandType ERROR showing here cmd.Parameters.Add( new SqlParameter ( "@searchvalue" , TextBox1.Text.ToString)); / / ERROR showing here SqlDataAdapter adp = new SqlDataAdapter (); cmd.Connection = con; con.open(); / / ERROR showing here adp = new SqlDataAdapter (cmd); adp.Fill(ds); / / ERROR showing here DataGrid1.DataSource = ds; / / ERROR showing here DataGrid1.DataBind can ceck rest of your code where ever you are creating a new instance of SqlCommand object. You are givning incorrect parameters there. Make sure whereever you have created an instance