Wednesday, 16 July 2014

To create connection string for database connectivity

Creating connection string for database connectivity:

Control panel -> Administrative tools -> Data sources ODBC -> Add button  -> select sql server  -> type the Name and server and click on NEXT -> click on NEXT -> select the database from the list and click on NEXT  -> click on FINISH -> click on Test Data source -> OK -> OK.


 Now steps in Visual studio

1. From toolbox select Data -> SqlDataSource


















2. Select the  symbol as shown in fig.  click on configure Data source




3. New connection -> select the name of database and server name and click OK  ->  NEXT ->  NEXT  > select the database name and check on *   -> next   test query -> FINISH





























This will create database connectivity for transferring data from asp to database and vise verso

In the web.config file, you will get the connectionstring added automatically.

<configuration>
    <connectionStrings>
        <add name="studConnectionString" connectionString="Data Source=DESAI-PC\SQLEXPRESS;Initial Catalog=stud;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>


copy the connection string for use at the time of coding.





Saturday, 29 September 2012

FIle upload in ASP .NET


3. File upload:
















Code for upload button:

 protected void Btnupload_Click(object sender, EventArgs e)
    {
        int sizelimit = 5242880;
        if (FileUpload1.HasFile)
        {
            if (FileUpload1.PostedFile.ContentLength <= sizelimit)
            {
                string path = "c:\\upload\\" + FileUpload1.FileName;
                FileUpload1.SaveAs(path);
                Label1.Text = "file uploaded to " + path;
            }
            else
                Label1.Text = "file exceeds size limit.";
        }
    }

AJAX UPDATE PANEL


2. AJAX UPDATE PANEL







<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
</script>

    <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Button Text="update" ID="btn_update" runat="server" />
        <%=DateTime.Now.ToString() %>
        </ContentTemplate>
        </asp:UpdatePanel>

    
    </div>
    </form>

</body>
</html>

Tuesday, 18 September 2012

ASP .NET


1.To save data from text box to database:




Naming: 
1. Textbox for name: txtname
2.Textbox for city: txtcity
3. Button for submit: btnsubmit
4.Button for clear: btnclear


In the namespace you must use the following namespace for database connectivity.

using System.Data.SqlClient;

Code for submit button:      


string str = "Data Source=DESAI-PC\\SQLEXPRESS;Initial Catalog=new1;Integrated Security=True";
 SqlConnection con = new SqlConnection(str);
 con.Open();
string sql = "insert into text2db values('" + txtname.Text + "','" + txtcity.Text + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();


Code for clear button: 

txtname.Text = "";
txtcity.Text = "";