hihi

i am a newbiest on c# and window form

i am doing a web service, and use a form which contain a datagridview

but meet quite alot of problem

1. how to validate user input with database, like example, when the user insert a username, however the database have that data, i should prompt the user to enter another username

i try before in previous thread that i validate that particular column with only user can enter 0 or 1....

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/4532eab7-0881-4814-90f4-274215ee0108/

is it something similiar?

2. did i need a web method for this?cause i using web service to retrieve data

You need to post what you have done so far so that we can sugguest ways to improve it.

You will likely need to poll your database for the username in question using an SQL statement or stored procedure of some sort.

i couldn't get the prompt out message out...so meaning...in the form code...it does go to the if statment...it went directly to the else ...how to solve

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], brands[1], Convert.ToInt32(DGVBrand.CurrentRow.Cells[3].Value));
        BindBrand();
    
        }
    }

See what the sql statement actually is by debugging then run this manually in the database and see what you get.

There are some other good practice issues with your code but we can look at these after we have it functioning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.