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 8967601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:16:48+00:00 2026-06-15T17:16:48+00:00

I have datatable like this. uid m_code pass roleID 1 F2 F2 2 2

  • 0

I have datatable like this.

uid m_code  pass    roleID    
1   F2      F2      2    
2   S2      S2      0

And i want to let user log-in depending on their roles.

I tried using this code, but it isn’t working at all. Any help much appreciated.

        string user = textBox1.Text;
        string pass = textBox2.Text;

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("select * from login where m_code='" + user + "' and pass='" + pass + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);


        if(dt.Columns[3].ToString() == "0")
        {
            this.Hide();
            StudentUI s = new StudentUI();
            s.Show();
        }
        if (dt.Columns[3].ToString() == "1")
        {
            this.Hide();
            TeacherUI t = new TeacherUI();
            t.Show();
        }
        if (dt.Columns[3].ToString() == "2")
        {
            FacultyUI f = new FacultyUI();
            f.Show();
        }
        else
        {
            MessageBox.Show("Login Failed");
        }
  • 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-06-15T17:16:49+00:00Added an answer on June 15, 2026 at 5:16 pm

    I agree with Blachshma, you should use parameters to mitigate the risk of Sql Injections. In the meantime, let’s fix up your logic:

    if(dt.Rows.Count == 0)
    {
        MessageBox.Show("Login Failed");
        return;
    }
    
    string val = Convert.ToString(dt.Rows[0][3]);
    
    if(val == "0")
    {
        this.Hide();
        StudentUI s = new StudentUI();
        s.Show();
    }
    else if (val == "1")
    {
        this.Hide();
        TeacherUI t = new TeacherUI();
        t.Show();
    }
    else if (val == "2")
    {
        FacultyUI f = new FacultyUI();
        f.Show();
    }
    else
    {
        MessageBox.Show("Login Failed");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a on memory Datatable like this. I want to produce xml file
I have a datatable like this. User Unit Score kiran testing 2 kiran demo
I have a Datatable function like this public DataTable LoadCategory(SetupCategoryBO scBO) { DBConnect myConnection
I have a untyped DataTable that looks like this (srcTbl): date col_1 col_2 ...
i have an datatable like this. i have got the data from sqlserver and
I have a DataTable like this name age ------------ kumar 27 kiran 29 anu
i have an datatable like this. i am getting this data from an excel
I have a datatable and I want to filter this table with a company
I have a jsf datatable inside my form like this. <h:form id=personId> <h:dataTable id=hdatatable
I have a datatable something like this: | Col1 | Col6 | Col3 |

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.