Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hello

I have data table name=table
in that table i have columns= name ,phone number,zip code id

in form i have 4 textbox (same name as columns )

how to create search button when i type text in zip code and phone number and click search to populate name and id

and after that to click second button and send that text in another form and populate other 4 textbox (same name)

forms name is form 6 and other is form 7


can you help me

What I have tried:

I did create tableadaper and dataset
Posted
Updated 4-Apr-17 22:45pm
v2
Comments
RickZeeland 2-Apr-17 14:31pm    
And ? any luck with DataView ?

C#
cmd.CommandText = "SELECT CMC, [Site Name], [Phone Number], Zip_Code FROM site Where Zip_Code='" + Zipcode.Text + "'";

Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 
You can use a DataView, like this:
DataView dv = new DataView(table);
dv.RowFilter = "id = 1"; // query 
See: DataView RowFilter Syntax [C#][^]
 
Share this answer
 
This is my solution

private void Crt_clck_Click(object sender, EventArgs e)
{

{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT CMC, [Site Name], [Phone Number], Zip_Code FROM site Where Zip_Code='" + Zipcode.Text + "'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
 
Share this answer
 
Comments
CHill60 5-Apr-17 7:28am    
Never build a sql command using string concatenation

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