Showing posts with label .Net Programs. Show all posts
Showing posts with label .Net Programs. Show all posts

Friday, 11 July 2014

Read Excel File in C#

Read Excel File in C#:


Read Excel File in C#

Design a form in Visual studio add a button ,Add a folder upload and paste an excel data file.
Button Click event write the below code:

Coding:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string target = Server.MapPath("~/Upload");
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(System.IO.Path.Combine(target, FileUpload1.FileName));
            string connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;", System.IO.Path.GetDirectoryName(target + "\\" + FileUpload1.FileName));
            string cmdString = string.Format("SELECT * FROM {0}", System.IO.Path.GetFileName(target + "\\" + FileUpload1.FileName));
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmdString, connString);
            DataSet dataSet = new DataSet();
            dataAdapter.Fill(dataSet);
            GridView1.DataSource = dataSet.Tables[0];
            GridView1.DataBind();
        }       
    }
}

If this is not satisfactory for you write us to get assistance Contact Us
Learn more about excel:Shareyourconscience
Read More
Posted on 8:18:00 am
Categories: ,

Thursday, 12 June 2014

Login-page-coding-in-dotnet-using-C#

CODING OF LOGIN PAGE IN C#:

Login-page-coding-in-dotnet-using-C#

Login.aspx.cs:

Notes:-
1. You have create user interface using visual studio as in screen shot.
2. double click on login button and write down the below coding on button click event.
3.Here database name is JOB.
4. Table name is userregistration.

//first of all include all namespace 
//these has been added automatically in Visual Studio.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class Login : System.Web.UI.Page
{

   
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        //connection string
        SqlConnection con = new SqlConnection("server=localhost; database=JOB; Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select * from userregistration where username=@username and 

password=@password", con);

        cmd.Parameters.AddWithValue("@username", text_username.Text);
        cmd.Parameters.AddWithValue("@password", Text_password.Text);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Session["uid"] = dr["email"].ToString();
            Session["name"] = dr["username"].ToString();
            Response.Redirect("jobseeakerwelcome.aspx");

        }

        else
        {
          
            Label1.Text = "invalid username password ";
        }
     
    }
    }
Read More
Posted on 8:53:00 pm
Categories:

Tuesday, 8 October 2013

Transaction in .net By:Tanuj Kumar

share your conscience

Transaction Example in .Net Program:

//first of all take button click event
button click()
   {
//create SqlConnection class object      
SqlConnection con = new SqlConnection("Connnection string");
      SqlTransaction transaction;
//open connection
       con.Open();
//begin transaction
      transaction = con.BeginTransaction();
      try 
      {
         new SqlCommand("INSERT INTO Transaction " +
            "(Text) VALUES ('Row1');", con, transaction)
            .ExecuteNonQuery();
         new SqlCommand("INSERT INTO Transaction " +
            "(Text) VALUES ('Row2');", con, transaction)
            .ExecuteNonQuery();
         new SqlCommand("INSERT INTO transaction2 VALUES " +
            "('Die', 'Die', 'Die');", con, transaction)
            .ExecuteNonQuery();
         transaction.Commit();
      } 
      catch (SqlException sqlError) 
      {
         transaction.Rollback();
      }
      con.Close();
   }



Posted By:Tanuj Kumar 
On:Shareyourconscience

Read More
Posted on 11:54:00 pm
Categories:

Thursday, 29 August 2013

Generic Collection:Stack By:Tanuj Kumar

Share your conscience

Stack<t>: simple .net program to show working of stack collection.

The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
An introduction to DOT NET:
Generic collection: Stack
Generic means it support specific data type (int,float string..etc) 
Stack is LIFO Last in first out manner.
Here stack is used to save data and retrieved it in LIFO manner.
You can run program and see the working procedure of it.

Stack

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;

namespace stackgenriccollection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Stack<string> st = new Stack<string>();

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {

                MessageBox.Show("enter value in textbox");
            }
            else
            {
                st.Push(textBox1.Text);
                MessageBox.Show("inserted");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (st.Count > 0)
            {
                Object obj = new Object();
                obj = st.Pop();
                MessageBox.Show(obj.ToString());
            }
            else
            {

                MessageBox.Show("no element in stack");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

            if (st.Count <= 0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                Object obj = new Object();
                obj = st.Peek();
                MessageBox.Show(obj.ToString());
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(st.Count.ToString());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (st.Count <= 0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                if (st.Contains(textBox2.Text))
                {

                    MessageBox.Show("available");
                }
                else
                {
                    MessageBox.Show("not available");} } }  }     }


Posted By:Tanuj Kumar 
On:Shareyourconscience
Read More
Posted on 1:21:00 am
Categories:

Event:Adding a button on run time: By:Tanuj Kumar

Event    
Adding a button on run time:
Adding a button on run time

Adding a button on run time
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;

namespace eventbuttonexample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Button b1 = new Button();
            this.Controls.Add(b1);
            b1.Location = new Point(50, 50);
            b1.Size = new Size(100, 50);
            b1.BackColor = System.Drawing.Color.Aqua;
            b1.Text = "tanuj";
            b1.Click += new EventHandler(a);
        }
        private void  a(Object sender, EventArgs e)
        {
  MessageBox .Show ("button is clicked");}      }}
Adding a textbox on run time:

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;

{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TextBox tb = new TextBox();
            this.Controls.Add(tb);
            tb.Location = new Point(50, 50);
            tb.TextChanged +=new EventHandler(a);
            tb.BackColor = System.Drawing.Color.Aqua;
        }
        private void a(Object sender, EventArgs e) {

            MessageBox.Show("text is changed");
        }
    }
}


Posted By:Tanuj Kumar 
Read More
Posted on 1:19:00 am
Categories:

Event:Insert TextBox on RUN TIME By:Tanuj Kumar


Insert TextBox on RUN TIME

Insert TextBox on RUN TIME:-

Assignment1:
texbox on runtime

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;

namespace eventassignment1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int a, b=100, c=100;
        private void button1_Click(object sender, EventArgs e)
        {
           
            a = int.Parse(textBox1.Text);
            for (int i = 0; i < a; i++) {


                TextBox tb = new TextBox();
                this.Controls.Add(tb);
                tb.Location = new Point(b, c);
                b = b + 10;
                c = c + 10;
            }
        }
    }

}
Posted By:Tanuj Kumar 
On:Shareyourconscience
Read More
Posted on 1:19:00 am
Categories:

Saturday, 17 August 2013

SortedList By:Tanuj Kumar

Sortedlist collection
Sorted list
Sortedlist:
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
An introduction to DOT NET:
AddAdds an element with the specified key and value to a SortedList object.
ClearRemoves all elements from a SortedList object.
CloneCreates a shallow copy of a SortedList object.
ContainsDetermines whether a SortedList object contains a specific key.
ContainsKeyDetermines whether a SortedList object contains a specific key.
ContainsValueDetermines whether a SortedList object contains a specific value.
CopyToCopies SortedList elements to a one-dimensional Array object, starting at the specified index in the array.
Sorted list


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.Collections;


namespace sortedlistcollectionprogram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SortedList sl = new SortedList();
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {

                MessageBox.Show("Enter value in textboxes");
            }
            else
            {
                sl.Add(textBox1.Text, textBox2.Text);
                show();
                MessageBox.Show("added");
            }

        }
        public void show() {

            listBox1.Items.Clear();

            foreach (DictionaryEntry de in sl)
            {

                listBox1.Items.Add(de.Key +" "+de.Value);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (sl.Count <= 0)
            {

                MessageBox.Show("sortedlist is empty");
            }
            else
            {
                sl.Remove(textBox3.Text);
                show(); MessageBox.Show("removed successfully");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (sl.Contains(textBox4.Text))
            {
                MessageBox.Show("available");
            }
            else {

                MessageBox.Show("not available");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(sl.Count.ToString());
        }

       
    }
}

Posted By:Tanuj Kumar 
On:Shareyourconscience

Read More
Posted on 10:55:00 pm
Categories: