Thursday, 22 August 2013

How to insert records in Access table using Asp.Net


 protected void Button2_Click(object sender, EventArgs e)
    {

        try
        {

            OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\NWIND2.accdb");
            con.Open();
//if you want selected columns :
//I have created student table having stud_name,stud_address,stid(autoincremented)
            String q = "insert into student(stud_address)  values(@ad)";
            OleDbCommand cmd = new OleDbCommand(q, con);
            cmd.Parameters.AddWithValue("@ad", "meerut");

            if (cmd.ExecuteNonQuery() > 0)
                Response.Write("inserted");
            else
                Response.Write("not inserted");

        }
        catch (Exception ee) { }
    }

How to send mail using gmail authentication in Asp.Net



using System.Net;
using System.Net.Mail;
using System.Text;
using System.IO;
using System.Data.OleDb;




    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("brijeshmalasi@yahoo.com", "Gedutech");
            mailMsg.To.Add( new MailAddress("brjmalasi@gmail.com","global"));
         
            mailMsg.Subject = "hello";
            mailMsg.IsBodyHtml = true;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.Body = "this is test mail";
            mailMsg.Priority = MailPriority.Normal;
            mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.Credentials = new NetworkCredential("your gmail id", "password");
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            //you can also call client.Send(msg)
            client.Send(mailMsg);
           response.write("Sent");
        }
        catch (SmtpException ee)
        {
            Response.Write(ee);
        }


    }


Saturday, 17 August 2013

How to create pdf file in ASP.NET

If you want to insert image in pdf file using iTextSharp :

var image = iTextSharp.text.Image.GetInstance(Server.MapPath('your image path'));

// where u want your image  (x,y pixels)
image.SetAbsolutePosition(300,300);

document.Add(image)


*************here is code*******

 String imgname = (grid1.Rows[i].Cells[1].FindControl("imagelarge") as System.Web.UI.WebControls.Image).ImageUrl.ToString();
                        //var logo = iTextSharp.text.Image.GetInstance(Server.MapPath(imgname));
                        //Response.Write("img="+imgname);
                        totRequest += "<tr><td><img src="+Server.MapPath(imgname)+" height='100' width='100'></td>";
                        String pname = (grid1.Rows[i].Cells[2].FindControl("name") as Label).Text;
                        totRequest = totRequest + "<td>" + pname;
                        String color = (grid1.Rows[i].Cells[3].FindControl("col") as Label).Text;

Wednesday, 14 August 2013

How to Pass and returns objects via function in C#.Net


class Person
    {
        public int a, b;

        public Person(int x,int y)
        {
            a = x;
             b=y;
        }
        public Person() { }
        public static Person sum(Person pp, Person hh)
        {
            int x = pp.a + hh.a;
            int y = pp.b + hh.b;

            Person temp = new Person();
            temp.a = x;
            temp.b = y;
            return temp;
      //return "a="+a+"b="+b;
        }
         
    }


class A
{
static void Main(String []st)
 {

   Person pp = new Person(34, 60);
            Person hh = new Person(2, 5);

           Person ans = Person.sum(pp, hh);
           MessageBox.Show("a="+ans.a + "b=" + ans.b);
       

}
}


Tuesday, 6 August 2013

C# Dot Net Assignment



TASK FIRST 

Creata a form  as mentioned below in C#.

It will ask name Customer Name,Customer AccNo, Customer Bal, Customer Address.when you click on submit button all details must submit in class object using Constructor function. Class is as follows:
Class Bank
  {
  String name,address;
Int  accno,bal;
                Bank(String na,String add,int ano,int bal){  input data }
                Withdraw( int amt) {with amt}
Deposit(int amt) {dep amt}
checkStatement(int accno) {check statement here }
}

Further, when user click on deposit a new window should appear asking deposit amt .
Same should be followed in case of withdraw amt but in withdraw a module it must take care that if amt is not sufficient to be withdrawn an “warning message must display on MSG box”.

How to send Email By php when user fill registration Form


NOTE : you need to download  "class_email.php" file and save it in your main folder.

Here html form for Users:

********************************index.html***********************


<h5>Registraton Form</h5>
<form method="post" action="insert.php" id="ff" class="well span2" style="padding:10px 10px 10px 10px;margin-left:0px;margin-top:0px" >
<label>Your Name :</label><input type=text class="span2" required id="user" name="user" placeholder="Name :">
<label>Mobile No :</label><input type=text class="span2" required name="mob" id="mob" placeholder="Mobile No :">
<label>Email ID :</label><input type=text class="span2" required name="email" id="email" placeholder="Email ID :">
<label>Select Course</label>
<select class="span2" id="crs" name="crs" style="background:white;border:1px solid white;color:black">
<option value="" selected>-select-</option>
<option value="Career Courses">Career Course</option>
<option value="Training Programs">Training programs</option>
</select>
<label>Select Technology</label>
<select class="span2" id="tech" name="tech" style="background:white;border:1px solid white;color:black">
<option value="" selected>-select-</option>
<option value="android">Android</option>
<option value="C#net">.Net C#</option>
<option value="aspNet">Asp.Net</option>
<option value="phpMsql">Php,MySql</option>
<option value="jquery">Jquery</option>
<option value="htmlJavaCss">Html,JavaScript,CSS</option>
<option value="java">Java</option>
<option value="AjaxWebService">Ajax,WebServices</option>
<option value="WordPress">WordPress</option>
<option value="LinqWpfMvc">Linq,Wpf,Mvc</option>
</select>
<button id="bt" class="btn btn-primary">Submit</button>
<input type=reset value=reset class="btn">
</form>





**************************index.html ended here ***********************


Here is php Code sending Mail.


php file name : insert.php

<?php


$name = $_POST["user"];
$mobile = $_POST["mob"];
$email = $_POST["email"];
$course = $_POST["crs"];
$tech = $_POST["tech"];

//echo "hi, Your name is :$name \n mob:$mobile \n email:$email \n course : $course \n tech:$tech";

include( 'class_email.php');

     $ee= new email();

//below is your Server details with port number.

  $ee->set_server('smtp.gmail.com', 465); //465,597,25 ()


//In below line you have to specify your google valid email and password
  $ee->set_auth('abc@gmail.com','password');


  $ee->set_sender( 'sender Details here ', 'sender Mail here' );

//In array() function mention your list to whom you want to send email: you can specify more than one
//like below

$send_to =array('abc@yahoo.com','xyz@gmail.com','pqr@gmail.com');
  $subject = "Enquiry Mail:GEdutech";
  $body="<div style='border:2px solid blue'><table border='0' cellpadding='10'> <tr> <td>Enquiry Name  </td><td>$name</td></tr>
  <tr> <td>Mobile No: </td><td>$mobile</td></tr>
   <tr> <td>Email :  </td><td>$email</td></tr>
  <tr> <td>Course </td><td>$course</td></tr>
   <tr> <td>Technology  </td><td>$tech</td></tr></table> </div>";


  if( $ee->mail($send_to, $subject,$body))
  {
echo true;
}
 else
 {
echo false;
}


?>


String Questions : Java, C#,C, C++


Strings :
1)Write a program to do the following :
1)To output the question “Who is the inventor of JAVA ?”.
2)To accept an answer.
3)To print out “Good” and then stop, if the answer is correct.
4)To output the message “try again”, if the answer is wrong.
5)To display the correct answer when the answer is wrong even at the third attempt and stop.
2)Write a program to extract a portion of a character string and print the extracted string. Assume  that m characters are extracted , starting with the nth character.

3)Write a program, which will get text string and count all occurrences of a particular word.
4)Write a program to read the price of an item in decimal form (like 75.95) and print the output in paise (like  7595 paise).