Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string str2 = employNoTxtBox.Text;
            MySqlConnection MyCon = new MySqlConnection("server=localhost; Database = nikz; user id=root; password=nikhil; pooling=false;");

            MyCon.Open();

            MySqlCommand command = new MySqlCommand();

            command.Parameters.AddWithValue("@EmpNo", str2);
            command.Connection = MyCon;
            command.ExecuteNonQuery();
            MyCon.Close();
            

            MyCon.Open();
            string connectionString = "server=localhost;" + "database=nikz;" + "uid=root;" + "password=nikhil;";
            MySqlCommand command1 = new MySqlCommand();
            command1.Parameters.AddWithValue("@EmpNo", str2);
            string sql = "SELECT * FROM LFT_Employees WHERE Emp_no='" + str2 + "'";
            MySqlConnection connection = new MySqlConnection(connectionString);
            MySqlDataAdapter dataadapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            connection.Open();
            dataadapter.Fill(ds, "LFT_Employees_table");
            connection.Close();
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "LFT_Employees_table";



my problem is that i have to display records of that row whose emp_no is mention in textbox but i have to bind it to datagrid view so i m not able to do so help!!!
Posted
Updated 27-Jun-12 23:34pm
v2
Comments
Vani Kulkarni 28-Jun-12 5:35am    
What is the issue you are facing?
nkhldhar 28-Jun-12 5:42am    
can't figure out how to do it
AshishChaudha 28-Jun-12 7:35am    
what exception you are getting??

This is your code.
C#
string str2 = employNoTxtBox.Text;
            MySqlConnection MyCon = new MySqlConnection("server=localhost; Database = nikz; user id=root; password=nikhil; pooling=false;");
 
            MyCon.Open();
 
            MySqlCommand command = new MySqlCommand();
 
            command.Parameters.AddWithValue("@EmpNo", str2);
            command.Connection = MyCon;
            command.ExecuteNonQuery();
            MyCon.Close();
            
 
            MyCon.Open();
            string connectionString = "server=localhost;" + "database=nikz;" + "uid=root;" + "password=nikhil;";
            MySqlCommand command1 = new MySqlCommand();
            command1.Parameters.AddWithValue("@EmpNo", str2);
            string sql = "SELECT * FROM LFT_Employees WHERE Emp_no='" + str2 + "'";
            MySqlConnection connection = new MySqlConnection(connectionString);
            MySqlDataAdapter dataadapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            connection.Open();
            dataadapter.Fill(ds, "LFT_Employees_table");
            connection.Close();
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "LFT_Employees_table";

try adding this line to your code at Last Line. This will perfectly work.
C#
dataGridView1.DataBind();
 
Share this answer
 
Comments
nkhldhar 28-Jun-12 5:20am    
no actually there is some problem with the code
John Bhatt 28-Jun-12 15:53pm    
Can you please tell error message.
try this-
Write the code in the Textbox's TextChanged Event
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900