get data from database in to text box c# asp
i have grid view edit button , when user click edit the page will redirect to other page with textbox fields in url i was add {employee_ID} i want getdata from data base and put it in fields text box and when click edit it will edit in database
this gridview : http://prntscr.com/llgid0
and this is edit page with {Employee_ID} : http://prntscr.com/llgio4
html for edit page :
<body>
<form id="form2" runat="server">
<div>
Employee ID :
<asp:TextBox ID="id" runat="server" ></asp:TextBox>
<br />
Employee Name : <asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
Address :
<asp:TextBox ID="address" runat="server"></asp:TextBox>
<br />
Birthdate :
<asp:TextBox ID="birth" runat="server" TextMode="Date"></asp:TextBox>
<br />
Mobile No :<asp:TextBox ID="mobile" runat="server"></asp:TextBox>
<br />
Email :
<asp:TextBox ID="email" runat="server"></asp:TextBox>
<br />
Country :<asp:TextBox ID="co" runat="server"></asp:TextBox>
<br />
CityName :<asp:TextBox ID="city" runat="server"></asp:TextBox>
<br />
UserName :<asp:TextBox ID="user" runat="server"></asp:TextBox>
<br />
Password :<asp:TextBox ID="pass" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
</div>
</form>
<div>
</div>
</form>
<p class="auto-style1">
</p>
</body>
</html>
code behind in gridview page :
public partial class table : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
BindEmpGrid();
txtSearch.Enabled = false;
}
}
private void BindEmpGrid()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = null;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
con.Close();
}
}
protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearchBy.SelectedItem.Text == "All")
{
txtSearch.Text = string.Empty;
txtSearch.Enabled = false;
}
else
{
txtSearch.Enabled = true;
txtSearch.Text = string.Empty;
txtSearch.Focus();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
if (ddlSearchBy.SelectedItem.Text == "Employee_ID")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Employee_name")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Mobile")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
private void getEmpRecords(string searchBy, string searchVal)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
cmd = new SqlCommand("all", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchBy", searchBy);
cmd.Parameters.AddWithValue("@SearchVal", searchVal);
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
protected void grdEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdEmp.PageIndex = e.NewPageIndex;
BindEmpGrid();
}
protected void grdEmp_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void grdEmp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int EmpID = int.Parse(e.CommandArgument.ToString());
DeleteRecord(EmpID);
BindEmpGrid();
}
if (e.CommandName == "Edit")
{
string EmpID = e.CommandArgument.ToString();
Response.Redirect("update.aspx?Id="+ EmpID);
}
}
private void DeleteRecord(int EmpID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from Emp where Employee_ID = @a";
cmd.Parameters.AddWithValue("@a", EmpID);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
c# asp.net visual-studio
add a comment |
i have grid view edit button , when user click edit the page will redirect to other page with textbox fields in url i was add {employee_ID} i want getdata from data base and put it in fields text box and when click edit it will edit in database
this gridview : http://prntscr.com/llgid0
and this is edit page with {Employee_ID} : http://prntscr.com/llgio4
html for edit page :
<body>
<form id="form2" runat="server">
<div>
Employee ID :
<asp:TextBox ID="id" runat="server" ></asp:TextBox>
<br />
Employee Name : <asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
Address :
<asp:TextBox ID="address" runat="server"></asp:TextBox>
<br />
Birthdate :
<asp:TextBox ID="birth" runat="server" TextMode="Date"></asp:TextBox>
<br />
Mobile No :<asp:TextBox ID="mobile" runat="server"></asp:TextBox>
<br />
Email :
<asp:TextBox ID="email" runat="server"></asp:TextBox>
<br />
Country :<asp:TextBox ID="co" runat="server"></asp:TextBox>
<br />
CityName :<asp:TextBox ID="city" runat="server"></asp:TextBox>
<br />
UserName :<asp:TextBox ID="user" runat="server"></asp:TextBox>
<br />
Password :<asp:TextBox ID="pass" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
</div>
</form>
<div>
</div>
</form>
<p class="auto-style1">
</p>
</body>
</html>
code behind in gridview page :
public partial class table : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
BindEmpGrid();
txtSearch.Enabled = false;
}
}
private void BindEmpGrid()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = null;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
con.Close();
}
}
protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearchBy.SelectedItem.Text == "All")
{
txtSearch.Text = string.Empty;
txtSearch.Enabled = false;
}
else
{
txtSearch.Enabled = true;
txtSearch.Text = string.Empty;
txtSearch.Focus();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
if (ddlSearchBy.SelectedItem.Text == "Employee_ID")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Employee_name")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Mobile")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
private void getEmpRecords(string searchBy, string searchVal)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
cmd = new SqlCommand("all", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchBy", searchBy);
cmd.Parameters.AddWithValue("@SearchVal", searchVal);
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
protected void grdEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdEmp.PageIndex = e.NewPageIndex;
BindEmpGrid();
}
protected void grdEmp_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void grdEmp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int EmpID = int.Parse(e.CommandArgument.ToString());
DeleteRecord(EmpID);
BindEmpGrid();
}
if (e.CommandName == "Edit")
{
string EmpID = e.CommandArgument.ToString();
Response.Redirect("update.aspx?Id="+ EmpID);
}
}
private void DeleteRecord(int EmpID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from Emp where Employee_ID = @a";
cmd.Parameters.AddWithValue("@a", EmpID);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
c# asp.net visual-studio
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33
add a comment |
i have grid view edit button , when user click edit the page will redirect to other page with textbox fields in url i was add {employee_ID} i want getdata from data base and put it in fields text box and when click edit it will edit in database
this gridview : http://prntscr.com/llgid0
and this is edit page with {Employee_ID} : http://prntscr.com/llgio4
html for edit page :
<body>
<form id="form2" runat="server">
<div>
Employee ID :
<asp:TextBox ID="id" runat="server" ></asp:TextBox>
<br />
Employee Name : <asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
Address :
<asp:TextBox ID="address" runat="server"></asp:TextBox>
<br />
Birthdate :
<asp:TextBox ID="birth" runat="server" TextMode="Date"></asp:TextBox>
<br />
Mobile No :<asp:TextBox ID="mobile" runat="server"></asp:TextBox>
<br />
Email :
<asp:TextBox ID="email" runat="server"></asp:TextBox>
<br />
Country :<asp:TextBox ID="co" runat="server"></asp:TextBox>
<br />
CityName :<asp:TextBox ID="city" runat="server"></asp:TextBox>
<br />
UserName :<asp:TextBox ID="user" runat="server"></asp:TextBox>
<br />
Password :<asp:TextBox ID="pass" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
</div>
</form>
<div>
</div>
</form>
<p class="auto-style1">
</p>
</body>
</html>
code behind in gridview page :
public partial class table : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
BindEmpGrid();
txtSearch.Enabled = false;
}
}
private void BindEmpGrid()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = null;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
con.Close();
}
}
protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearchBy.SelectedItem.Text == "All")
{
txtSearch.Text = string.Empty;
txtSearch.Enabled = false;
}
else
{
txtSearch.Enabled = true;
txtSearch.Text = string.Empty;
txtSearch.Focus();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
if (ddlSearchBy.SelectedItem.Text == "Employee_ID")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Employee_name")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Mobile")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
private void getEmpRecords(string searchBy, string searchVal)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
cmd = new SqlCommand("all", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchBy", searchBy);
cmd.Parameters.AddWithValue("@SearchVal", searchVal);
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
protected void grdEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdEmp.PageIndex = e.NewPageIndex;
BindEmpGrid();
}
protected void grdEmp_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void grdEmp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int EmpID = int.Parse(e.CommandArgument.ToString());
DeleteRecord(EmpID);
BindEmpGrid();
}
if (e.CommandName == "Edit")
{
string EmpID = e.CommandArgument.ToString();
Response.Redirect("update.aspx?Id="+ EmpID);
}
}
private void DeleteRecord(int EmpID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from Emp where Employee_ID = @a";
cmd.Parameters.AddWithValue("@a", EmpID);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
c# asp.net visual-studio
i have grid view edit button , when user click edit the page will redirect to other page with textbox fields in url i was add {employee_ID} i want getdata from data base and put it in fields text box and when click edit it will edit in database
this gridview : http://prntscr.com/llgid0
and this is edit page with {Employee_ID} : http://prntscr.com/llgio4
html for edit page :
<body>
<form id="form2" runat="server">
<div>
Employee ID :
<asp:TextBox ID="id" runat="server" ></asp:TextBox>
<br />
Employee Name : <asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
Address :
<asp:TextBox ID="address" runat="server"></asp:TextBox>
<br />
Birthdate :
<asp:TextBox ID="birth" runat="server" TextMode="Date"></asp:TextBox>
<br />
Mobile No :<asp:TextBox ID="mobile" runat="server"></asp:TextBox>
<br />
Email :
<asp:TextBox ID="email" runat="server"></asp:TextBox>
<br />
Country :<asp:TextBox ID="co" runat="server"></asp:TextBox>
<br />
CityName :<asp:TextBox ID="city" runat="server"></asp:TextBox>
<br />
UserName :<asp:TextBox ID="user" runat="server"></asp:TextBox>
<br />
Password :<asp:TextBox ID="pass" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
</div>
</form>
<div>
</div>
</form>
<p class="auto-style1">
</p>
</body>
</html>
code behind in gridview page :
public partial class table : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
BindEmpGrid();
txtSearch.Enabled = false;
}
}
private void BindEmpGrid()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = null;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
con.Close();
}
}
protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearchBy.SelectedItem.Text == "All")
{
txtSearch.Text = string.Empty;
txtSearch.Enabled = false;
}
else
{
txtSearch.Enabled = true;
txtSearch.Text = string.Empty;
txtSearch.Focus();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
if (ddlSearchBy.SelectedItem.Text == "Employee_ID")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Employee_name")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else if (ddlSearchBy.SelectedItem.Text == "Mobile")
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
else
{
getEmpRecords(ddlSearchBy.SelectedItem.Text, txtSearch.Text.Trim());
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
private void getEmpRecords(string searchBy, string searchVal)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
cmd = new SqlCommand("all", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchBy", searchBy);
cmd.Parameters.AddWithValue("@SearchVal", searchVal);
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
else
{
grdEmp.DataSource = dt;
grdEmp.DataBind();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();
cmd.Dispose();
con.Close();
}
}
protected void grdEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdEmp.PageIndex = e.NewPageIndex;
BindEmpGrid();
}
protected void grdEmp_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void grdEmp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int EmpID = int.Parse(e.CommandArgument.ToString());
DeleteRecord(EmpID);
BindEmpGrid();
}
if (e.CommandName == "Edit")
{
string EmpID = e.CommandArgument.ToString();
Response.Redirect("update.aspx?Id="+ EmpID);
}
}
private void DeleteRecord(int EmpID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from Emp where Employee_ID = @a";
cmd.Parameters.AddWithValue("@a", EmpID);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
c# asp.net visual-studio
c# asp.net visual-studio
asked Nov 22 '18 at 7:17
MohammedMohammed
14
14
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33
add a comment |
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33
add a comment |
1 Answer
1
active
oldest
votes
If you redirect into other page with id then multiple solution available.
1) Using query string id fetch detail from database and fill value.
2)Store your data into session when you click on edit button and then fetch detail from your sessionid into other page/form.
public void fetchEmployeeDetail()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp where number =" + Request.QueryString["id"], con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
name.Text = dt.rows[0]["name"].ToString(); // name means your table column name
address.Text = dt.rows[0]["name"].ToString();
birth.Text = dt.rows[0]["name"].ToString();
}
}
catch
{
}
}
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
|
show 11 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425681%2fget-data-from-database-in-to-text-box-c-sharp-asp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you redirect into other page with id then multiple solution available.
1) Using query string id fetch detail from database and fill value.
2)Store your data into session when you click on edit button and then fetch detail from your sessionid into other page/form.
public void fetchEmployeeDetail()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp where number =" + Request.QueryString["id"], con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
name.Text = dt.rows[0]["name"].ToString(); // name means your table column name
address.Text = dt.rows[0]["name"].ToString();
birth.Text = dt.rows[0]["name"].ToString();
}
}
catch
{
}
}
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
|
show 11 more comments
If you redirect into other page with id then multiple solution available.
1) Using query string id fetch detail from database and fill value.
2)Store your data into session when you click on edit button and then fetch detail from your sessionid into other page/form.
public void fetchEmployeeDetail()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp where number =" + Request.QueryString["id"], con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
name.Text = dt.rows[0]["name"].ToString(); // name means your table column name
address.Text = dt.rows[0]["name"].ToString();
birth.Text = dt.rows[0]["name"].ToString();
}
}
catch
{
}
}
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
|
show 11 more comments
If you redirect into other page with id then multiple solution available.
1) Using query string id fetch detail from database and fill value.
2)Store your data into session when you click on edit button and then fetch detail from your sessionid into other page/form.
public void fetchEmployeeDetail()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp where number =" + Request.QueryString["id"], con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
name.Text = dt.rows[0]["name"].ToString(); // name means your table column name
address.Text = dt.rows[0]["name"].ToString();
birth.Text = dt.rows[0]["name"].ToString();
}
}
catch
{
}
}
If you redirect into other page with id then multiple solution available.
1) Using query string id fetch detail from database and fill value.
2)Store your data into session when you click on edit button and then fetch detail from your sessionid into other page/form.
public void fetchEmployeeDetail()
{
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
adp = new SqlDataAdapter("select * from Emp where number =" + Request.QueryString["id"], con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
name.Text = dt.rows[0]["name"].ToString(); // name means your table column name
address.Text = dt.rows[0]["name"].ToString();
birth.Text = dt.rows[0]["name"].ToString();
}
}
catch
{
}
}
edited Nov 22 '18 at 7:33
answered Nov 22 '18 at 7:28
A.M. PatelA.M. Patel
689
689
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
|
show 11 more comments
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
Yes please wite for me code to fetch data from database and fill it in to textbox depend on employee_ID from query string in url number = 34 please see pic :prnt.sc/llgio4
– Mohammed
Nov 22 '18 at 7:31
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
where i put this code ? in edit page ?
– Mohammed
Nov 22 '18 at 7:38
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
If you are publishing this project and want to use this code posted by 'user2156791': I would really recommend you to read about and learn how to use SQL parameters to secure your DB against SQL injections..
– heap1
Nov 22 '18 at 7:42
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
see this : prntscr.com/llgtzz
– Mohammed
Nov 22 '18 at 7:43
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
@Mohammed copy the connection string from your previous page and past in editpage and use it.
– A.M. Patel
Nov 22 '18 at 7:48
|
show 11 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425681%2fget-data-from-database-in-to-text-box-c-sharp-asp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
so where's the problem?
– JohnB
Nov 22 '18 at 7:25
How to get data according in query string in url from employee_ID and put it in filed textbox ? i want function to retrieve data depend on querystring from url , note : querystring number=Employee_id from data base
– Mohammed
Nov 22 '18 at 7:28
so you expect us to just write the code for you ?
– JohnB
Nov 22 '18 at 7:32
at least have an attempt and we can help you when you get any errors
– JohnB
Nov 22 '18 at 7:33