Sunday, 2 February 2014

How to create EXE in Visual Studio

1. Open Visual Studio.
2. Open your Project.
3. From Solution Explorer right-click Solution (project)--> Add -->New Project ...




















4. Select Other Project Types --> Setup and Deployment --> Visual Studio Installer --> Select Setup Wizard. Write a name and click OK.




















5. Click Next.






































6. Select Create a setup for windows application.

7. Click Next.
8. Select Primary Output from Project.
9. Click Next.


10. Click Add and select your app config file.


11. Click Open.
12. Click Next and then Finish.


13. Click Finish.


14. Click the Application folder at the left side.

15. Right Click Application Folder and add Project Icon that you want to set.



16. Select Icon.


18. Now Right Click Primary Output and Click Create a shortcut to Primary Output from Project.

19. Give a name to exe. and from shortcut property set Icon.


20. Now Drag and Drop Exe to User's Desktop.


21. Now-Again Create shortcut and Drag and Drop it to User's Program Menu.


22. Now From Solution Explorer -- > Select Project and From--> View -- >Select Properties Window.

23. Set Publisher name and company name. 

24. Now Right Click Setup from Solution Explorer. And click Build.

25. In Project Folder you will find EXE in the Release folder.

26. Install Exe and check.





Friday, 24 January 2014

Passing QueryString in Asp.net

1. Open Visual Studio
2. Create a New Website
3. Add web page
4. from Website - >Add New Item -> WebPage- > Click Add.
5. Add Button Control.

6. Write code in button click event as below

   protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("DashBoard.aspx?username=sapna&password=123456");
    }

7. Add New Page named DashBoard.aspx

8. Add Two label controls in DashBoard.aspx.

9. Write code inside Page_Load Event as below.


 protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["username"] != null && Request.QueryString["password"]!=null)
        {
            lblusername.Text = Request.QueryString["username"].ToString();
            lblpassword.Text = Request.QueryString["password"].ToString();
        }
    }

10. Run Code you will get querystring values in two labels.

Saturday, 30 November 2013

Bind Value into Dropdown List from Database

1. Open Visual Studio
2. Create a New Website
3. Add web page
4. from WEbsite - >Add New Item -> WebPage- > Click Add.
5. From ToolBox -> Add DropdownList to WebPage.
6. Create StoredProcedure of Select Query.


7. Add namespaces to page

using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;


8. Write Connection String

  static string str = WebConfigurationManager.ConnectionStrings["conn"].ConnectionString;
    SqlConnection con = new SqlConnection(str);

9. Write Code on Page Load Event

 if (!Page.IsPostBack)
        {
            SqlCommand cmd = new SqlCommand("Select_Employee", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = cmd;
            da.Fill(ds);


            if (ds.Tables[0].Rows.Count > 0)
            {
                DropDownList1.DataSource = ds;
                
                DropDownList1.DataTextField = "EmpName";
                DropDownList1.DataValueField = "EmpID";
                DropDownList1.DataBind();
            }
        }

10. Click F5.

Monday, 18 November 2013

Background color of textbox on focus

1. Open Visual Studio
2. Create a New Website
3. Add web page
4. from WEbsite - >Add New Item -> StyleSheet- > Click Add.
5. Write code in the css file



.txt
{

}
.txt:focus
{
    background-color:Red;
}

6. Add css to the web page's head section.

<link rel="stylesheet" type="text/css" href="Styles/Site.css" />

7. Add TextBox to a web page.

  <asp:TextBox ID="txt1" runat="server" CssClass="txt" ></asp:TextBox>

8. Click F5



Monday, 16 September 2013

How to view Data from Database

 1. Open Visual Studio
2. Create a New Website
3 From Database - > Select Stored Procedure -> Right Click - > Add New Stored Procedure.
4. Create Select Query for Employee Table.

5.  Create a method in class for select.


public DataSet Select_Employee()
    {
        SqlCommand cmd = new SqlCommand("Select_Employee", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = cmd;
        da.Fill(ds);
        return ds;
    }

6. Add Web Page and Place Gridview.
7. Add namaspace 
using System.Data

8. On Page_Load write Code as below.

 DataSet ds = new DataSet();
    mainClass objmain = new mainClass();
    
    protected void Page_Load(object sender, EventArgs e)
    {

        ds = objmain.Select_Employee();
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }

9. Click F5.

Sunday, 15 September 2013

How to Insert Data in Database

1. Open Visual Studio
2. Create a New Website
3. From Website - > Add New Item -> SQL Server Database -> Add.
4. From Server Explorer Expand your Database -> Right Click - > Add New Table.



5. From Database - > Select Stored Procedure -> Right Click - > Add New Stored Procedure.
6. Create Insert Query for Employee Table.


7. Add connection string in Web.Config File.

<connectionStrings>
<add name="conn" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=G:\Asp.net_Controls\App_Data\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>


8. From Website -> Add New Item -> Class -> Give name  -> Click Add.
9. Add namespaces to Class File.

using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;


10. Create a method in class for the insert.

    static string str = WebConfigurationManager.ConnectionStrings["con"].ConnectionString;
    SqlConnection con = new SqlConnection(str);
    int i;


    public int insert_Employee(string EmpName, string EmpAddress, string EmpPhone, string EmpMobile,      string EmpSalary, string EmpPassport)
    {
        try
        {
            SqlCommand cmd = new SqlCommand("insert_Employee", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EmpName", EmpName);
            cmd.Parameters.AddWithValue("@EmpAddress", EmpAddress);
            cmd.Parameters.AddWithValue("@EmpPhone", EmpPhone);
            cmd.Parameters.AddWithValue("@EmpMobile", EmpMobile);
            cmd.Parameters.AddWithValue("@EmpSalary", EmpSalary);
            cmd.Parameters.AddWithValue("@EmpPassport", EmpPassport);
            i = cmd.ExecuteNonQuery();
            return i;
        }
        catch (Exception ex)
        {
            return i = 0;
        }
    }


11. Add web Page. and Design UI.


12. Write Code on Button click event.

 mainClass objMain = new mainClass();
    int i;
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        i = objMain.insert_Employee(txtname.Text, txtadress.Text, txtphone.Text, txtmobile.Text, txtsalry.Text, txtpassport.Text);
        if (i > 0)
        {
            Response.Write("<script language='javascript'>alert('Successfully inserted!');</script>");
        }
        else
        {
            Response.Write("<script language='javascript'>alert('Error try again!');</script>");
        }
    }

13. Click F5.

Tuesday, 10 September 2013

Using SqlDataSource in Asp.net

1. Open Visual Studio
2. Create a New Website
3. Create a New Web Page.
4. Place GridView on-page.
5.From GridView Properties Select-> DataSourceID -> New DataSource.



6. Click OK.


7. Click Next.
8. Select Table Name and Columns and click Next.


9. Click Finish.
10. Click F5





SQL server tricky questions