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

I am a newbie with Spring MVC but I'm quite impressed with its capabilities.
I am quite newbie to autoit. I have 2 questions. How to use ControlFocus
I'm a newbie in XUL programming and I learned many things but I'm having
Newbie question: There are three types of Asp.Net controls : HTML server controls, Web
I'm completely newbie to Qt i want to create a 800X600 window that just
Hello I'm a newbie web programmer. My background is writing Windows applications with sql.
First: I'm JavaScript newbie. So.. I have basic form with password, repeat password, email
ASP.NET newbie here. I would like to create a form with multiple types of
I'm an extreme newbie at C#, but I've been slowly moving through the Head
Sorry for the newbie question. I have a UITabBar in my main window view

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.