TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sakshi Kaul
NA
72
7.2k
How to retrieve data from database in textboxes
Apr 3 2019 1:39 AM
Hi
I want when employee enters emp id in text box and press enter then the corresponding other details present in the registration form should be entered and by default all text box should be kept disable and when the user clicks on edit button then he should be able to edit the text (enter the information) and when he clicks on registration button then the data should be saved in other table and on clear button again the new page should be loaded
I have done coding for registration button that will save data in the table.
What all changes should be done in order to implement above scenario ?
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.Sql;
using
System.Data.SqlClient;
using
System.Data;
using
System.Configuration;
public
partial
class
_Default : System.Web.UI.Page
{
SqlCommand cmd =
new
SqlCommand();
SqlConnection con=
new
SqlConnection();
protected
void
Page_Load(
object
sender, EventArgs e)
{
con.ConnectionString = @
"Data Source=SAKSHIKAUL-LT\SQLEXORESS1;Initial Catalog=registrationForm;Integrated Security=True"
;
con.Open();
{
if
(!
this
.IsPostBack)
Label1.Text =
""
;
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{ SqlCommand cmd =
new
SqlCommand(
"insert into RegistrationTable"
+
"(EmpId,Nationality,Religion,Gender,Address,EmailId,Hobbies,MaritalStatus) values (@EmpId,@Nationality,@Religion,@Gender,@Address,@EmailId,@Hobbies,@MaritalStatus)"
, con);
//string insertQuery = "insert into RegistrationTable(EmpId,Nationality,Religion,Gender,Address,EmailId,Hobbies,Maritalstatus)values (@EmpId,@Nationality,@Religion,@Gender,@Address,@EmailId,@MHobbies,@Maritalstatus)";
cmd.Parameters.AddWithValue(
"@EmpId"
, TextBox1.Text);
cmd.Parameters.AddWithValue(
"@Nationality"
, TextBox2.Text);
cmd.Parameters.AddWithValue(
"@Religion"
, TextBox3.Text);
cmd.Parameters.AddWithValue(
"@Gender"
, TextBox4.Text);
cmd.Parameters.AddWithValue(
"@Address"
, TextBox5.Text);
cmd.Parameters.AddWithValue(
"@EmailId"
, TextBox6.Text);
cmd.Parameters.AddWithValue(
"@Hobbies"
, TextBox7.Text);
cmd.Parameters.AddWithValue(
"@Maritalstatus"
, TextBox8.Text);
cmd.ExecuteNonQuery();
Label1.Text =
"Registered Successfuly"
;
}
protected
void
Button2_Click(
object
sender, EventArgs e)
{
cmd.CommandText =
"update RegistrationTable set Nationality =' "
+ TextBox2.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set Religion =' "
+ TextBox3.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set Gender =' "
+ TextBox4.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set Address =' "
+ TextBox5.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set EmailId =' "
+ TextBox6.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set Hobbies =' "
+ TextBox7.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.CommandText =
"update RegistrationTable set MaritalStatus =' "
+ TextBox8.Text +
"' where EmpId='"
+ TextBox1.Text +
"' "
;
cmd.Connection = con;
cmd.ExecuteNonQuery();
Label1.Text =
"Updated Successfuly"
;
}
protected
void
Button3_Click(
object
sender, EventArgs e)
{
TextBox1.Text =
""
;
TextBox2.Text =
""
;
TextBox3.Text =
""
;
TextBox4.Text =
""
;
TextBox5.Text =
""
;
TextBox6.Text =
""
;
TextBox7.Text =
""
;
TextBox8.Text =
""
;
Label1.Text =
"Clear All"
;
}
protected
void
SqlDataSource1_Selecting(
object
sender, SqlDataSourceSelectingEventArgs e)
{
}
protected
void
TextBox1_TextChanged(
object
sender, EventArgs e)
{
}
}
Reply
Answers (
10
)
Security - It is recommended to not send any sensitive Info
MVC Partial Views