I am creating a system that allow applicant to apply for a job,
so i am having different forms which content many textboxs and dropdownlist.
The first form content FirstName,Last Name and other Personal info, second form to ask them about their Qualification. And these two form in different pages. So, After filling the Personal Info the applicant should click NEXT to fill the Qualification info.
Can any one tell me how to insert the applicant info into database Using C#, Please !
OhoudKhalid
0 Points
5 Posts
How to Insert data from textboxs into database!!
May 01, 2012 05:46 AM|LINK
Hi everyone,
I have a question in Visual Studio 2010
I am creating a system that allow applicant to apply for a job,
so i am having different forms which content many textboxs and dropdownlist.
The first form content FirstName,Last Name and other Personal info, second form to ask them about their Qualification. And these two form in different pages. So, After filling the Personal Info the applicant should click NEXT to fill the Qualification info.
Can any one tell me how to insert the applicant info into database Using C#, Please !
what are the codes for the Personal info Page?
Thanks
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 05:53 AM|LINK
Create an SQL Statement and use ExecuteNonQuery for inserting data Or use SqlDataSource.
Ex:
protected void btnInsert_Click(object sender, EventArgs e) { SqlDS.InsertCommandType = SqlDataSourceCommandType.Text; SqlDS.InsertCommand = "Insert into emp (Name,F_Name) VALUES (@Name, @F_Name)"; SqlDS.InsertParameters.Add("Name", txtName.Text); SqlDS.InsertParameters.Add("F_Name", txtFName.Text); SqlDS.Insert(); txtName.Text = ""; txtFName.Text = ""; }http://www.codeproject.com/Tips/331181/How-to-insert-Data-in-SQL-server-via-SqlDataSource
Also after this is working, you can move sql query to stored procedures in sql server for performance.
http://www.codeproject.com/Articles/17667/Insert-and-retrieve-data-through-stored-procedure
OhoudKhalid
0 Points
5 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 06:25 AM|LINK
It will work if I have a Button in the page
I have a HyperLink only !
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 06:35 AM|LINK
This would work with any server side control.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 06:39 AM|LINK
hi
change your hyperLink to linkbutton
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
and do what nijhawan.saurabh in click event of link button
linkbutton have look and feel as hyperlink
and do the response.redirect also inside click event
bhushan_bhar...
Participant
1515 Points
597 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 06:48 AM|LINK
Have a look this link.....
http://usingaspdotnet.blogspot.in/2011/03/add-delete-update-inside-gridview-using.html
Useofasp.net/
Howtouseasp.net
poojajoon
Member
228 Points
52 Posts
Re: How to Insert data from textboxs into database!!
May 01, 2012 07:18 AM|LINK
Hey
The code to insert the value of textboxes in database is
Code at Default.aspx page is:
<table width="60%">
<tr>
<td align="center">First Name:</td>
<td align="center">
<asp:TextBox ID="txt_firstname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="center">Last Name:</td>
<td align="center">
<asp:TextBox ID="txt_lastname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</td></tr>
</table>
Code at Default.aspx.cs file is:
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
string strconn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(strconn);
//just to replace ' with '' not to through exception while inserting
String first_name = txt_firstname.Text;
String replacefirstname = first_name.Replace("'", "''");
String last_name = txt_lastname.Text;
String replacelastname = last_name.Replace("'", "''");
String strinsert = "insert into table_name values('" + replacefirstname.ToString() + "','" + replacelastname.ToString() + "')";
SqlCommand cmd = new SqlCommand(strinsert, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
Hope this will help you.