locked
Adapt sql database code to MS Access database RRS feed

  • Question

  • User-1324141504 posted

     Could someone please adapt the attached C# login code for sql server to suit MS Access database. The table will still be called users.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["SmsConnectionString"].ConnectionString;
            string checksql = "select * from users where UserName='" + Login1.UserName.ToString() + "' and password='" + Login1.Password.ToString() + "'";
            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                myConnection.Open();
                SqlCommand myCommand = new SqlCommand(checksql, myConnection);
                myCommand.ExecuteNonQuery();
                da.SelectCommand = myCommand;
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    myConnection.Close();
                    Response.Redirect("Home.aspx");
    
                }
    
    
                else
                {
    
                    return;
                }
            }
        }
    }


     

    Thursday, August 19, 2010 5:14 AM

Answers

  • User197322208 posted

    sqlconnection=> oledbconnection

    sqlcommand =>oledbcommand

    and so on

    but ... did you think what happens if the user pass his name as :

    '; drop table users;

    ;-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 19, 2010 6:54 AM

All replies