get data from database in to text box c# asp












-2















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">
&nbsp;</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();


}
}









share|improve this question























  • 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
















-2















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">
&nbsp;</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();


}
}









share|improve this question























  • 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














-2












-2








-2








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">
&nbsp;</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();


}
}









share|improve this question














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">
&nbsp;</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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












1 Answer
1






active

oldest

votes


















0














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
{

}
}





share|improve this answer


























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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
{

}
}





share|improve this answer


























  • 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
















0














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
{

}
}





share|improve this answer


























  • 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














0












0








0







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
{

}
}





share|improve this answer















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
{

}
}






share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith