2 Replies - 871 Views - Last Post: 23 June 2011 - 05:01 AM Rate Topic: -----

#1 cutexxbaby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-June 11

why cant prompt the message when validate user input to database c#

Posted 22 June 2011 - 07:13 PM

hihi i am newbiest in window form and c#
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();
        
       }
        
       
       
    
      }



Is This A Good Question/Topic? 0
  • +

Replies To: why cant prompt the message when validate user input to database c#

#2 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: why cant prompt the message when validate user input to database c#

Posted 23 June 2011 - 04:40 AM

What is your problem exactly? That the message does not display? Are you sure the code is getting here? Try putting a breakpoint on the line
MessageBox.Show("BrandName is allocated");


and checking that the line is executed. If not put a breakpoint on line 3 of the btnAdd_Click method and use F11 to step through each line until you find the reason the line is not called (my guess is that validate.validateBrandName(txtBrandName.Text) returns false...)
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,635
  • Joined: 23-August 08

Re: why cant prompt the message when validate user input to database c#

Posted 23 June 2011 - 05:01 AM

Debugging Tutorial
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1