Click here to Skip to main content
16,016,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI...

I had a gridview table in which i insert the records..(product name, qty etc..). Now i want to check the existing product name is inserted or not....

Any Suggestions will help me a lot......

Thanks..
Posted

1 solution

Don't ever search your control. Search your database.
 
Share this answer
 
Comments
nithibs 12-Jul-11 5:25am    
Ya.. I do that and write a piece of code...
if (ddliname.SelectedItem.Text.ToString())
{
cmd = new SqlCommand("Select p_name from Quote_pro_details where p_name='" + ddliname.SelectedItem.Text + "'", con);
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
string i = ds.Tables[0].Rows[0][0].ToString();
if (i!=0)
{
lblmsg3.Visible = true;
lblmsg3.ForeColor = System.Drawing.Color.Red;
lblmsg3.Text = "Product already entered";
}
}


I dont know how to implement it in if condition.... i am getting error..........
Christian Graus 12-Jul-11 5:28am    
Tell us the error if you want help. However, I don't think this is what you want. I suspect you get an error when there's no data returned, because the NUMBER of rows is 0, there's no 0 returned. Use select count(*) to get the number or fix your code to check if ds.Tables[0].Rows.Count is 0.
nithibs 12-Jul-11 6:13am    
Hi...

Thanks... i got solution for the above code as you mentioned...

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