i am doing a webservice and use window form to consume it
however i meet some problem, i have a textbox in window form...user input the brandname and when click on the button , it should check if the brandname exist in the database, if it does it should prompt me, but i try out and read all and google...i couldnt find a solution...
thanks in advance
this is my web method...
[WebMethod]
public Boolean validateBrandName(String txtBrandName)
{
SqlConnection conn =
new SqlConnection("Data Source=.\\SQLEXPRESS;
Initial Catalog=Brand;Integrated Security=True");
SqlCommand dbCommand = new SqlCommand();
dbCommand.CommandText =
@"SELECT COUNT(*)
FROM Brand
WHERE BrandName='" + txtBrandName + "'";
// this text box name is from the window form
dbCommand.Connection = conn;
conn.Open();
int matchesCount = int.Parse(dbCommand.ExecuteScalar().ToString());
conn.Close();
return matchesCount != 0;
}
then this is my form code
private void btnAdd_Click(object sender, EventArgs e)
{
WSBrandData validate = new WSBRandData();
if (validate.validateBrandName(txtBrandName.Text))
{
MessageBox.Show("BrandName is allocated");
txtUserName.Text = "";
}
else
{
WSBrandData add = new WSBRandData();
String[] brands = null;
brands = Convert.ToString(DGVBrand.CurrentRow.Cells[1].Value).Split(';');
String tagg = txt.Text + ";";
brands[1] = tagg;
DGVBrand.DataSource = add.addBrandName(Convert.ToInt32(DGVBrand.CurrentRow.Cells[0].Value), brands[0], brand[1], Convert.ToInt32(DGVBrand.CurrentRow.Cells[3].Value));
BindBrand();
}
}

New Topic/Question
Reply



MultiQuote





|