Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:48:46+00:00 2026-05-23T06:48:46+00:00

I am a newbie with c# and window form I am doing a web

  • 0

I am a newbie with c# and window form

I am doing a web service, and use a form which contain a datagridview, but am having quite a lot of problems.

How do I validate user input with a database, for example, when the user inserts a username, however the username already exists in the database, I should prompt the user to enter another username.

I tried before in previous thread that I validate that particular column with only user can enter 0 or 1….

how to validate particular column cell field when editing
Is it something similar?

Do I need a web method for this?

p.s basically what I want is to have a textbox field in a window form, in which the user will key in a username to add it to the database, however, when they click on the add button, if the user name already exists, there will be a prompt. If not it will add it to database using the insert web method.

The data is retrieve by web method… meaning that I have to use a web method to help me with this check right…but how?

my code for web method

[WebMethod]  
public DataSet validateUserName()  
{   

    SqlConnection conn = 
        new SqlConnection("Data Source=.\\SQLEXPRESS;
            Initial Catalog=User;Integrated Security=True");   
    SqlCommand dbCommand = new SqlCommand();  
    dbCommand.CommandText = 
        @"SELECT COUNT(*) 
        FROM User 
        WHERE UserName=@UserName"; 
    // this textusername is from the window form  
    dbCommand.Connection = conn;  
    SqlDataAdapter da;   
    da = new SqlDataAdapter();   
    da.SelectCommand = dbCommand;

    DataSet ds = new DataSet();  
    da.Fill(ds);   
    return ds;

}

this is my window form code

private void btnAdd_Click(object sender, EventArgs e)

{
    WSBrandData validate = new WSBRandData();
    if (validate.validateUserName(txtUserName.Text))
    {
        MessageBox.Show("UserName is allocated");
        txtUserName.Text = "";
    }
    else
    {
       WSBrandData add = new WSBRandData();

        String[] names = null;

        names = Convert.ToString(DGVBrand.CurrentRow.Cells[1].Value).Split(';');
        String tagg = txtUserName.Text + ";";
        names[1] = tagg;

        DGVBrand.DataSource = add.addUserName(Convert.ToInt32(DGVBrand.CurrentRow.Cells[0].Value), names[0], names[1], Convert.ToInt32(DGVBrand.CurrentRow.Cells[3].Value));
        BindBrand();

    }




}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:48:47+00:00Added an answer on May 23, 2026 at 6:48 am

    Start here :

    [WebMethod]  
    public Boolean UserNameExists(String userName)  
    {   
    
        SqlConnection conn = 
            new SqlConnection("Data Source=.\\SQLEXPRESS;
                Initial Catalog=User;Integrated Security=True");   
        SqlCommand dbCommand = new SqlCommand();  
        dbCommand.CommandText = 
            @"SELECT COUNT(*) 
            FROM User 
            WHERE UserName='" + userName + "'";
        // this textusername is from the window form  
        dbCommand.Connection = conn;  
    
        conn.Open();
    
        int matchesCount = int.Parse(dbCommand.ExecuteScalar().ToString());
    
        conn.Close();  
    
        return matchesCount != 0;
    
    }
    

    In your forms application:

    if (webReference.Type.UserNameExists(this.userNameTextBox.Text) )
    {
        // Do something
    }
    else
    {
        // Do something else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.NET newbie here... I'd like to make a button in a Windows form that
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
Total newbie question but this is driving me mad! I'm trying this: myInt =
Well it's kind of a newbie question but I think lots of people have
Hello I'm a newbie web programmer. My background is writing Windows applications with sql.
ASP.NET newbie here. I would like to create a form with multiple types of
I'm quite a novice with C# and a complete newbie regarding WPF. Probably it's
I've been having a lot of trouble trying to render text in SDL with
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.