Saturday, March 24, 2012

conform password

private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string d = "select name,pass from pass where name='" + label1.Text + "' and pass='" + textBox6.Text + "'";
                SqlCommand cmd1 = new SqlCommand(d, con);
                con.Open();
                SqlDataReader dr = cmd1.ExecuteReader();
               
                if (dr.Read() == true)

                {
                    dr.Close();
                    if (textBox3.Text == textBox4.Text)
                    {
                       
                        string s = "update pass set pass='" + textBox4.Text + "' where pass='" + textBox6.Text + "' and name='" + label1.Text + "'";
                        SqlCommand cmd = new SqlCommand(s,con);
                       
                        cmd.ExecuteNonQuery();
                    
                       
                        MessageBox.Show("entered succesfully");
                       
                    }
                    else
                    {
                        MessageBox.Show("password mismatch");
                    }
                }
                else
                {
                    MessageBox.Show("invalid currentpassword");
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }

Thursday, March 15, 2012

Stored procedures


Insert:
create procedure spinsert(@UserId nvarchar(50),@UserName nvarchar(50)=null)
as
begin
insert into proc1 values(@UserId,@UserName)
end


delete:
create proc spdelete(@UserId nvarchar(50)=null)
as
begin
delete from proc1 where UserId=@UserId
end


Update:

create proc spupdate(@UserId nvarchar(50)=null,@UserName nvarchar(50)=null)
as
begin
update proc1 set UserId=@UserId,UserName=@UserName where UserId=@UserId
end
select:
create proc spselect(@UserId nvarchar(50)=null,@UserName nvarchar(50)=null)
as
begin
select UserName from proc1 where UserId=@UserId
end



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace stp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlConnection con = new SqlConnection("uid=sa;password=123;database=naseer");

      

 private void insert_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("spinsert",con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserId",textBox1.Text);
            cmd.Parameters.AddWithValue("@UserName",textBox2.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("inserted succesfully");
        }

      

 private void delete_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("spdelete", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserId", textBox1.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("deleted succesfully");
        }

      


 private void update_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("spupdate", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserId", textBox1.Text);
            cmd.Parameters.AddWithValue("@UserName", textBox2.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("updated succesfully");
        }


     
 private void select_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("spselect", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserId", textBox1.Text);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                textBox2.Text = dt.Rows[0]["UserName"].ToString();
            }
            else
            {
                MessageBox.Show("Please enter Correct UserID");
            }
            
         
        }

    }
}



Thanks&Regards,
Naseer.

Tuesday, March 13, 2012

validations in windows applications(C#.net)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace FecilitiesMgt
{
    public partial class AddNewUser : Form
    {
        public AddNewUser()
        {
            InitializeComponent();
        }
        SqlConnection con = new SqlConnection("uid=sa;password=123;database=FacilityMgt");
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Form f = new AdminMenu();
            f.Show();
            this.Hide();
        }


        private void btnsubmit_Click(object sender, EventArgs e)
        {
            if (txtname.Text == "" || txtprsno.Text == "" || txtrank.Text == "" || txtcont.Text == "" || txtmail.Text == "" || txtuser.Text == "" || txtpwd.Text == "")
            {
                MessageBox.Show(this, "Enter all fields", "Facility", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else
            {
                string s = "insert into adduser values('" + txtname.Text + "','" + txtprsno.Text + "','" + txtrank.Text + "','" + txtcont.Text + "','" + txtmail.Text + "','" + txtuser.Text + "','" + txtpwd.Text + "')";
                SqlCommand cmd = new SqlCommand(s, con);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("User added");
                txtname.Text = txtprsno.Text = txtrank.Text = txtcont.Text = txtmail.Text = txtuser.Text = txtpwd.Text = "";
             
            }
        }

        private void txtcont_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) == false)
            {
                MessageBox.Show("Enter digit Only");
                e.Handled = true;
            }
        }

        private void txtname_Leave(object sender, EventArgs e)
        {
            if (txtname.Text == "")
            {
                MessageBox.Show("Enter name");
                txtname.Focus();
            }
        }

        private void txtprsno_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (char.IsDigit(e.KeyChar) == false)
            {
                MessageBox.Show("Enter digit Only");
                e.Handled = true;
            }
        }

        private void txtuser_Leave(object sender, EventArgs e)
        {
            if (txtuser.Text.Length < 6)
            {
                MessageBox.Show(this, "username should not be less than 6 characters", "username", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtuser.Focus();
            }

        }

        private void txtpwd_Leave(object sender, EventArgs e)
        {
            if (txtpwd.Text.Length < 6)
            {
                MessageBox.Show(this, "password: min 6 characters ", "password", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtpwd.Focus();
            }
        }

        private void txtcont_Leave(object sender, EventArgs e)
        {
            if (txtcont.Text == "")
            {
                MessageBox.Show("Enter Mobile number");
                txtcont.Focus();
            }
        }

        //private void AddNewUser_Load(object sender, EventArgs e)
        //{

        //}

        private void txtname_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtprsno_Leave(object sender, EventArgs e)
        {
            if (txtprsno.Text == "")
            {
                MessageBox.Show("Enter personal no");
                txtprsno.Focus();
            }
        }

        private void txtrank_Leave(object sender, EventArgs e)
        {
            if (txtrank.Text == "")
            {
                MessageBox.Show("Enter Rank");
                txtrank.Focus();
            }
        }

        private void txtmail_Leave(object sender, EventArgs e)
        {
            //if (txtmail.Text == "")
            //{
            //    MessageBox.Show("enter Email-ID");
            //    txtmail.Focus();
            //}

            if (!Regex.Match(txtmail.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success)
            {
                MessageBox.Show(txtmail.Text+ " is Invalid Email");
                txtmail.Focus();
            }



        }

        private void txtcont_Validating(object sender, CancelEventArgs e)
        {
            if (txtcont.Text.Length != 10)
            {
                MessageBox.Show(this, "contact number must 10 numbers", "Contact", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtcont.Focus();
            }
        }

        private void lblname_Click(object sender, EventArgs e)
        {

        }

        private void txtname_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar) == false)
            {
                MessageBox.Show("Enter text only");
                txtname.Focus();
            }
        }}

Friday, October 28, 2011

My B.Tech life

Its really amazing ,i studied at MRRITS Udayagiri in CSE Department,i am a 2010 passed out,my B.Tech life is a collection of memories i even can't forgot a single memory,i come up with lot of problems ,stunts,risks,daring,friends,fear everything i tasted every thing in B.Tech at finally 64.13%. 

My intermediate life

Its really nice and also energetic life,people with innocence always concentration on studied,preparing for Eamcet,quarries between friends fights nice life and also unforgettable life.finally 85.5%

My school life

My life is not as much grate as big people,simple and calm going life i studied in the school name Shanthinikethan high school its in nellore.finally 74.1%