Sunday 24 September 2017

How to create Attractive Forms in html-5 using some Css code

Copy and paste the code in your html file:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Forms </title>

<style>
body
{ margin:0 auto;
padding:0px;
background-color:#99C;
background-image:url(img/1.jpg);
background-size:cover;
}

form
{
margin:0 auto;
width:350px;
height:600px;
background-color:#F6F;
margin-top:100px;
border-radius:50px 20px 50px 20px;
color:#93F;
border:8px   inset #90F;
font-style:italic;
font-weight:bold;
opacity:0.6;

background-image:url(img/2.jpg);
}
TD{
padding:20PX;}

</style>



</head>

<body>

<form>
<br>
<br>

<table>

<tr>
<td> User Name: </td>

<td>
<input type="text" size="15"  required="required" maxlength="10"/>

 </td>
 </tr>

<tr>
<td> Password: </td>
<td> <input type="password" size="15"  required="required"/>  </td>
 </tr>


<tr>
<td> Gender: </td>
<td>
<input type="radio"value="male" name="gender"/>Male <input type="radio" value="Female" name="gender"/>Female
 </td>

 </tr>


<tr>

<td>Education </td>
<td>
<input type="checkbox"  name="EDU" value="SSC"/>SSC
<input type="checkbox"  name="EDU" value="HSC"/>HSC
<input type="checkbox"  name="EDU" value="GRADUATION"/>GRAD
   </td>

</tr>




<TR>

<TD> City: </TD>
<TD>
<select>
<option value="khi">Karachi</option>
<option value="lhr">Lahore</option>
<option value="isb">Islamabad</option>
<option value="MUL">Multan </option>

</select>

</TD>

</TR>

<tr>

<td>Upload Resume: </td>
<td> <input type="file"/>  </td>

</tr>


<tr>

<td> </td>
<td><button> Submit!</button> </td>

</tr>


</table>



</form>


</body>
</html>


How to export From sql records to data Grid view

Database to Data Grid view:


            string connectionString = null; //connection string
            string sql = null; //query from db

            connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User ID=sa;Password=aptech";
            SqlConnection cnn = new SqlConnection(connectionString); //con object
            cnn.Open(); //coneection open form db
            sql = "SELECT * FROM student"; //query
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn); //reads all records from db
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

How to export database table in excel file (From SQL TO EXCEL)

Button event Code:

  SqlConnection cnn;
            string connectionString = null;
            string sql = null;
            string data = null;
            int i = 0;
            int j = 0;

            Microsoft.Office.Interop.Excel.Application xlApp;
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Microsoft.Office.Interop.Excel.Application();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User             ID=sa;Password=aptech";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = "SELECT * FROM student";
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
                {
                    data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
                    xlWorkSheet.Cells[i + 1, j + 1] = data;
                }
            }

            xlWorkBook.SaveAs(@"C:\Users\salman\Desktop\csharp-Excel6.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);

            MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");

Release Method outside button event :

private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...