narasiman rao

narasiman rao

  • NA
  • 519
  • 768.4k

Using Grid view how to check Vendor name already exists

Dec 6 2012 2:02 AM
i am doing application using grid view.in that i am inserting the record as VendorFName, VendorLName,VendorCity,VendorState,VendorCountry,VendorDescription etc.
in that i am using VendorID as Primary Key.

suppose when i insert one record VendorFName, VendorLName,VendorCity,VendorState,VendorCountry,VendorDescription it is saved in the database.
suppose again i am repeating the same VendorFName and click the new ADDROW Button i want to show the message VendorFName already exists.

for that how to write the code using csharp.

i send my code as follows;from my code how to write the code VendorFName already exists.


protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       if (e.CommandName.Equals("AddNew"))
        {
      
                TextBox txtFName = (TextBox)ResultGridView.FooterRow.FindControl("txtFName1");
                TextBox txtLName = (TextBox)ResultGridView.FooterRow.FindControl("txtLName1");
                TextBox txtCity = (TextBox)ResultGridView.FooterRow.FindControl("txtCity1");
                TextBox txtState = (TextBox)ResultGridView.FooterRow.FindControl("txtState1");
                TextBox txtCountry = (TextBox)ResultGridView.FooterRow.FindControl("txtCountry1");
                TextBox txtDescription = (TextBox)ResultGridView.FooterRow.FindControl("txtDescription1");
                SqlConnection conn = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
       

                cmd.Connection = conn;
                cmd.CommandText = "INSERT INTO Vendors(VendorFName, VendorLName,VendorCity,VendorState,VendorCountry,VendorDescription) Values('" + txtFName.Text + "', '" + txtLName.Text + "', '" + txtCity.Text + "', '" + txtState.Text + "', '" + txtCountry.Text + "' , '" + txtDescription.Text + "')";
                conn.Open();
                cmd.ExecuteNonQuery();
                FillVendorGrid();
                conn.Close();
            }
       }

Answers (2)