display insert query data in datagridview?
i have form with some textboxes and a button to insert data into database and below the form i have datagridview in to insert data from the form to the database and automatically display inserted datafrom datagridview ... i want to textbox textchange event for display data in datagridview not button click event?

Iftikar HussainPosted Aug 14, 2013, 3:19 AM
You can write query on textchange event
Regards,
Iftikar
Prasenjit DeyPosted Aug 14, 2013, 3:52 AM
private void txtBox1_TextChanged(object sender, EventArgs e)
{
int searchData = Convert.ToInt32(textBox1.Text);
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection(@"Data Source=SqlServer;Initial Catalog=TestDb;Persist Security Info=True;User ID=TestUser;Password=TestPassword"))
{
if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
conn.Open();
string sql = "Select * from YourTable where Year like '%@searchData %' ";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@searchData ", searchData);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp .Fill(dt);
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
}
honar abubakrPosted Aug 14, 2013, 3:45 AM
Sunny SharmaPosted Aug 14, 2013, 3:16 AM
Yes, you can do this. Please share your aspx page.
honar abubakrPosted Aug 14, 2013, 2:49 AM
i have windows form with four textboxes txt1,txt2,txt3,txt4 and a button bt1
my form is for insertind data from textboxes into database,i use bt1 click event to insert data into database. and under the form i have datagridview ... i want to use txt3 textchange event to display data in my database table in datagridview.
for ex/ in txt3 i have year i want to say in textbox textchange display data in datagridview when txt3.text = any year?
is my question clear or not?
Prasenjit DeyPosted Aug 14, 2013, 2:33 AM