C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Inserting records


Posted Date: 21 Aug 2008      Total Responses: 2

Posted By: Sonia sardana       Member Level: Silver     Points: 1


Hey Frnds, I m New to the ASP.Net..Plz Help me out.
I want to Insert the Records into the Database on Image Click, I know how to Insert Records On Button Click.I want to Ask that procedure is same or different to insert Records On Image Click.




Responses

Author: Gaurav Agrawal    21 Aug 2008Member Level: GoldRating:     Points: 6
protected void btn_add_Click(object sender, EventArgs e)
{
adpt1 = new MySql.Data.MySqlClient.MySqlDataAdapter("select * from tbluser limit 0,0", cn);
adpt1.Fill(ds, "user");
bld = new MySql.Data.MySqlClient.MySqlCommandBuilder(adpt1);
DataRow r = ds.Tables["user"].NewRow();
r["name"] = Convert.ToString(txt_nmadd.Text);
r["password"] = Convert.ToString(myfn.GenerateTinyUrlKey(8));
r["fathersname"] = Convert.ToString(txt_fnmadd.Text);
r["address"] = Convert.ToString(txt_addressadd.Text);
r["ph_no"] = Convert.ToString(txt_phadd.Text);
r["qulification"] = Convert.ToString(txt_qualificationadd.Text);
r["email_id"] = Convert.ToString(txt_emailadd.Text);
r["utype"] = Convert.ToInt16(ddl_utypeadd.SelectedValue);
r["dept_id"] = Convert.ToInt16(ddl_deptadd.SelectedValue);
r["sub_status"] = 0;
check(txt_nmadd, txt_emailadd);
try
{
ds.Tables["user"].Rows.Add(r);
adpt1.Update(ds.Tables["user"]);
string ext = System.IO.Path.GetExtension(fileupload_add.FileName);
ext = ext.ToUpper();
MySql.Data.MySqlClient.MySqlDataAdapter ad1 = new MySql.Data.MySqlClient.MySqlDataAdapter("select * from tbluser where enroll_no=(select max(enroll_no) from tbluser)", cn);
ad1.Fill(ds, "user1");
bld = new MySql.Data.MySqlClient.MySqlCommandBuilder(ad1);
DataRow r1 = ds.Tables["user1"].Rows[0];
if (fileupload_add.FileName != "")
{
try
{
switch (ext)
{
case ".JPEG":
r1["photo"] = Convert.ToString("photo_" + r1["enroll_no"] + ".jpeg");
fileupload_add.SaveAs(Server.MapPath("u_photos/photo_" + r1["enroll_no"] + ".jpeg"));
ad1.Update(ds.Tables["user1"]);
break;
case ".JPG":
r1["photo"] = Convert.ToString("photo_" + r1["enroll_no"] + ".jpg");
fileupload_add.SaveAs(Server.MapPath("u_photos/photo_" + r1["enroll_no"] + ".jpg"));
ad1.Update(ds.Tables["user1"]);
break;
case ".GIF":
r1["photo"] = Convert.ToString("photo_" + r1["enroll_no"] + ".gif");
fileupload_add.SaveAs(Server.MapPath("u_photos/photo_" + r1["enroll_no"] + ".gif"));
ad1.Update(ds.Tables["user1"]);
break;
}
}
catch { }
}
mail(Convert.ToInt16(r1["enroll_no"]));
adpt = new MySql.Data.MySqlClient.MySqlDataAdapter("select * from tbluser_type", cn);
adpt.Fill(ds, "tutype");
DataRow tr = ds.Tables["tutype"].Select("type='Student'")[0];
if (Convert.ToInt16(ddl_utypeadd.SelectedValue) == Convert.ToInt16(tr["utype_id"]))
Response.Redirect("stdcourse.aspx?action=add");
tr = ds.Tables["tutype"].Select("type='Lecturer'")[0];
if (Convert.ToInt16(ddl_utypeadd.SelectedValue) == Convert.ToInt16(tr["utype_id"]))
Response.Redirect("lecsub.aspx?action=add");
Response.Redirect("user.aspx");
}
catch { }
}



Author: Appukuttan    22 Aug 2008Member Level: DiamondRating:     Points: 6
Put Imagebutton ,for that give image through Image URL.

For that button's click u write ur code.


public void save_Records()
{
string strFname, strLname, strTitle, strCity, strQuey;
SQLHelper addEmployee = new SQLHelper();
strFname = txtFName.Text;
strLname = txtLName.Text;
strTitle = txtTitle.Text;
strCity = txtCity.Text;
if (Session["EmpId"] == null)
{
strQuey = "insert into employees(firstname,lastname,title,city)values('" + strFname + "','" + strLname + "','" + strTitle + "','" + strCity + "')";
}
else
{
strQuey = "update employees set firstname='" + strFname + "',lastname='" + strLname + "',title='" + strTitle + "',city='" + strCity + "' where employeeid='" + Session["EmpId"] + "'";
}
int rec=addEmployee.ExecuteNonQuery(strQuey);
if (rec > 0)
{
Response.Redirect("GridViewNew.aspx");
}

}



SQLHelper.cs.txt
Post Reply
You must Sign In to post a response.
Next : problem with session
Previous : AJAX Validatorcallout control
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

teleconferencing service

Contact Us    Privacy Policy    Terms Of Use