Aim:
To perform the Asp.net application in c# windows form.
Algorithm:
Step 1:Open the visual studio 2010 and select the file menuànew websiteàwindows c# àAsp.Net empty fileàfile nameàok.
Step2:Design the form as per the Asp.Net application to connect database.
Step3:Add (usingSystem.Data.OleDb;) in the program.
Step 4: Use OleDbConnection con, OleDbCommandcmd,to connect a database.
Step 5 :Create a object for OleDbConnection , OleDbCommandand get the values from the user.
Step 6 :Type a code for save button.
stringqry = "insert into tbl_student values ('" + txtregno.Text.ToString() + "','" + txtsname.Text.ToString() + "')";
cmd = new OleDbCommand(qry, con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Step 7: Compile and run the program without error.
PROGRAM
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Data.OleDb;
usingSystem.Configuration;
publicpartialclass_Default : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommandcmd;
protectedvoidPage_Load(object sender, EventArgs e)
{
con = newOleDbConnection();
con.ConnectionString =
ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString;
if(con.State == ConnectionState.Closed)
con.Open();
}
protectedvoidBtnSave_Click(object sender, EventArgs e)
{
stringqry = "insert into tbl_student values ('"+ txtregno.Text.ToString() + "','"+
txtsname.Text.ToString() + "')";
cmd = newOleDbCommand(qry, con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Response.Write("Saved Successfully");
}
}
OUTPUT:
BY
REGU RAM SV.
إرسال تعليق