using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.SqlClient;
namespace
WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlConnection
sqlcon = new SqlConnection(@"//Connection String//");
SqlCommand
sqlcom = new SqlCommand();
SqlDataAdapter
sqlada = new SqlDataAdapter();
DataSet
dset = new DataSet();
AutoCompleteStringCollection
namesCollection = new AutoCompleteStringCollection();
public
Form1()
{
InitializeComponent();
}
private
void Form1_Load(object
sender, EventArgs e)
{
if
(sqlcon.State == ConnectionState.Open)
sqlcon.Close();
sqlcon.Open();
sqlcom.Connection = sqlcon;
sqlcom.CommandText = "select * from TableName where Columnname
like'" + txtNames.Text + "%'";
sqlcom.ExecuteNonQuery();
sqlada.SelectCommand = sqlcom;
sqlada.Fill(dset, " TableName ");
for (int i = 0; i < dset.Tables["TableName "].Rows.Count; i++)
{
namesCollection.Add(dset.Tables["Autocomplete"].Rows[i]["Names"].ToString());
}
txtNames.AutoCompleteMode = AutoCompleteMode. SuggestAppend;
txtNames.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtNames.AutoCompleteCustomSource =
namesCollection;
}
}
}

No comments:
Post a Comment
Comment Here..