using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
using System.Configuration;

namespace hepsi_web_form
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox txtUserName;
        protected System.Web.UI.WebControls.RequiredFieldValidator rvUserNameValidator;
        protected System.Web.UI.WebControls.TextBox txtPassword;
        protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
        protected System.Web.UI.WebControls.ValidationSummary validationSummery1;
        protected System.Web.UI.WebControls.Label lblMessage;
        protected System.Web.UI.WebControls.Label lblMessage2;
        protected System.Web.UI.WebControls.Button cmdSubmit;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
        }
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
        private void InitializeComponent()
        {   
            this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion



        private void cmdSubmit_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
                {
                    FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, false);
                }
                else
                {
                    lblMessage.Text = "Invalid Login, please try again!";
                }
            }
            Response.Redirect("secimForm.aspx");
        }

        private bool DBConnection(string txtUser, string txtPass)
        {
            OleDbConnection myConn = new OleDbConnection(ConfigurationSettings.AppSettings["strConn"]);
            OleDbCommand myCmd = new OleDbCommand("EMPLOYEES", myConn);
            myCmd.CommandType = CommandType.StoredProcedure;

            OleDbParameter objParam1;
            OleDbParameter objParam2;
            OleDbParameter returnParam;

            objParam1 = myCmd.Parameters.Add ("@FIRST_NAME", OleDbType.VarChar);
            objParam2 = myCmd.Parameters.Add ("@EMPLOYEE_ID", OleDbType.VarChar);

            returnParam = myCmd.Parameters.Add ("@NUMBER_OF_EMP", OleDbType.VarChar);

            objParam1.Direction = ParameterDirection.Input;
            objParam2.Direction = ParameterDirection.Input;
            returnParam.Direction = ParameterDirection.Input;

            objParam1.Value = txtUser;
            objParam2.Value = txtPass;

            try
            {
                if (myConn.State.Equals(ConnectionState.Closed))
                {
                    myConn.Open();
                    myCmd.ExecuteNonQuery();
                }

                OleDbDataReader objReader;
                objReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection);


                if ((int)returnParam.Value < 1)
                {
                    lblMessage.Text = "Invalid Login!";
                    return false;
                }
                else
                {
                    myConn.Close();
                    return true;
                }
            }


                /*  while(objReader.Read())
                    {

                        if (objReader.GetValue(0) = 0)
                        {
                            lblMessage.Text = "Invalid Login!";
                            //return false;
                        }
                        else
                        {
                            objReader.Close();
                            return true;
                        }

                    }*/     



            catch (Exception ex)
            {
                lblMessage2.Text = ex + "Error Connecting to the database";
                return false;
            }

        }   

    }
}

this my code ı have problem with this my Error is :

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

Requested Url: /hepsi_web_form/secimForm.aspx

My database is Oracle 9i

Edited 3 Years Ago by pyTony: fixed formating

Hi Aslıhan,

It seems your web server (IIS I suppose) gives you a standart 404 which means that the URL you requested isn't there; so this has nothing to do with your ASP.Net code. (ASP.Net uses a technology called Code Behind which separates the page design from code unlike regular ASP. Each page has a .aspx page design with related code residing on a different file with same name having .cs extension instead.) Please check wether you have /hepsi_web_form/secimForm.aspx on your web server. If not you might need to change your project settings to place those files under /inetpub/wwwroot/hepsi_web_form/ .
If you are Turkish and need help w/ C#, ASP.Net or anything programing related you can PM me in Turkish.

Loren Soth

I have a problem with c#, this is my first c# program so I have many difficulties.someone help!!! :o

I use oracle 9i
here is my code;

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox nameBox;
    protected System.Web.UI.WebControls.TextBox surnameBox;
    protected System.Web.UI.WebControls.TextBox userId;
    protected System.Web.UI.WebControls.TextBox date;
    protected System.Web.UI.WebControls.Calendar Calendar1;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.Button button;

    private void Page_Load(object sender, System.EventArgs e)
               {        
        if(!Page.IsPostBack)
        {
            DataBind();
        }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
        InitializeComponent();
        base.OnInit(e);
    }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private void InitializeComponent()
    {    
                   this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged);
        this.button.Click += new System.EventHandler(this.button_Click);
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
    {
        date.Text=Calendar1.SelectedDate.ToShortDateString();
    }

    private void button_Click(object sender, System.EventArgs e)
               {
          OleDbDataAdapter da = new OleDbDataAdapter
          ("SELECT first_name FROM employees",
          @"Provider=MSDAORA.1;Data  Source=****;Password=*****;User ID=****;" );
          DataSet ds = new DataSet();
          da.Fill(ds, "employees");
          DataGrid1.DataSource = ds.Tables["employees"].DefaultView ;
          DataGrid1.DataBind();
    }


    }
}

//////////////////////////////////////////////////////
//in select part, I want to take the variables from textboxes,
//which the names are; nameBox, surnameBox, userId, date.
// by these variables it will show me, daily working plan of an employee
how can ı get them from textboxes and how can I put them in to the select part
/////////////////////////////////////////////////////

Edited 3 Years Ago by Dani: Formatting fixed

mrb cok sevındım dılımden anlayan bıryle karsılasmama...
ya ılk defa c# kullanıorum ve bıraz zorlk cekıorum
asagıdakı kotlarla, bır employeenin gunluk yapması gereken ıslerı datagridde gostermeye calışıorum
eger select kısmında herseyı bellı edersem ozaman bı problem yok o kısıye ait yapması gereken ısler cıkıyor
ama benım amacım dısardan textboxtan verılerı almak ve bunu nasıl selecte gostercemı bılmıorum bi kaç yol denedım ama sonuç cıkartmadı yardımcı olursan cok sevınırım

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox nameBox;
protected System.Web.UI.WebControls.TextBox surnameBox;
protected System.Web.UI.WebControls.TextBox userId;
protected System.Web.UI.WebControls.TextBox date;
protected System.Web.UI.WebControls.Calendar Calendar1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button button;

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DataBind();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged);
this.button.Click += new System.EventHandler(this.button_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
date.Text=Calendar1.SelectedDate.ToShortDateString();
}

private void button_Click(object sender, System.EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter
(" SELECT J.JOBS_TYPE, J.JOBS_DATE
FROM JOBS J, EMPLOYEES E
WHERE J.EMPLOYEE_ID=E.EMPLOYEE_ID
AND E.EMPLOYEE_ID='102' '",
@"Provider=MSDAORA.1;Data Source=****;Password=*****;User ID=****;" );
DataSet ds = new DataSet();
da.Fill(ds, "employees");
DataGrid1.DataSource = ds.Tables["employees"].DefaultView ;
DataGrid1.DataBind();
}


}
}

Selam,

Kodda aşağıdaki değişikliği yaparsan userid'si girilen çalışanın işleri gözükecektir. (TextBox'a geçerli bir employee_id girildiğini varsayıyorum.) Diğer textboxlar için de benzer SQL queryler yazılabilir o zaman da button'a basıldığında önce hangi textbox'ın (yada textboxların) dolu olduğuna bakıp ona göre gereken query içinde gerekli yere ilgili_textbox.Text'i ekleyerek bind edebilirsin. (Aslında query'ler içinde dilden bağımsız variable kullanmayı sağlayan bir SQL standardı da var ama burada gerek yok.) Oracle yerine MS SQL Server kullanmanı öneririm, ileride başın daha az ağrır, ama gördüğüm kadarıyla Oracle'la örnek olarak gelen database üzerinde işlem yapıyorsun. Sanırım ingilizce yazmayarak forum kurallarını ihlal ediyoruz ama istersen bana forumdan PM yada email atabilirsin.

AND E.EMPLOYEE_ID='"+userId.Text+"' '",

Loren Soth

This article has been dead for over six months. Start a new discussion instead.