Click here to Skip to main content
16,017,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to retrieve one column of data from my table and i want to check that column data is contain the data that i enter in my textbox

string t = "select Name from Product";
SqlDataAdapter fd = new SqlDataAdapter(t, DbConnection.mCon);
DataTable dtcc = new DataTable();
fd.Fill(dtcc);
//if (dtcc.Rows[0][0].ToString() == TextBox1.Text)
if(dtcc.Columns[0].ToString()==TextBox1.Text)


i have table named product and one field named in Name

i have one textbox suppose i enter a name in that textbox i want to check that name is
occure in my database or not
Posted
Comments
minal21 14-Dec-12 0:40am    
Asking same question again...here the solution for that question http://www.codeproject.com/Questions/508715/retrievingpluscolumnplusdataplusandpluscheckpluswi
(see solution 1)

1 solution

You would be able to do this better if you try using the value of the textbox in the query itself.
For e.g.
SqlCommand cmd = new SqlCommand("select name from Product where name like @City", conn);
SqlParameter param  = new SqlParameter();
param.ParameterName = "@Name";
param.Value         = textbox1.text;
cmd.Parameters.Add(param);
reader = cmd.ExecuteReader();

If the reader returns a count of 1 or more, a record with this name already exists.
 
Share this answer
 
v2
Comments
ravuravu 13-Dec-12 11:42am    
suppose i enter a name in textbox i want to check that the name is already in database or not if it not i want to add the name or i want to update the name with further details
Member 9581488 13-Dec-12 14:52pm    
You may use TextChanged Event of textbox

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