how to write sp for the above and implement in .aspx page..
need to get selected value from dropdownlist and textbox
need to get selected value from dropdownlist and textbox and than make the filter condition to pass value from code to stored procedure..
Kumar SambhavPosted May 23, 2013, 6:11 AM
cmd.Connection = con;
public void BindData()
{
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sam_proc_MyProcedure";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.Add(new SqlParameter("@roll", SqlDbType.VarChar)).Value = ddlDropDown.SelectedValue;
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar)).Value = txtTextBox.Text;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("TableName");
da.Fill(dt);
con.Close();
gdvMyDetails.DataSource = dt;
gdvMyDetails.DataBind();
}
parthiban karnanPosted May 23, 2013, 2:29 AM
this code not working...
public void BindData()
Kumar SambhavPosted May 22, 2013, 9:00 AM
{
MyMethod(Convert.ToInt32(ddlSearching.SelectedValue.ToString()), Convert.ToInt32(txtMySalary.Text.ToString()));
}
public void MyMethod(int DropDownloaValue, int TextBoxValue)
{
SqlConnection con = new SqlConnection("");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sam_proc_MyProcedure";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Selection_Type", 1);
cmd.Parameters.AddWithValue("@EmpType", DropDownloaValue);
cmd.Parameters.AddWithValue("@Salary", TextBoxValue);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet("MyTable");
da.Fill(ds, "MyTable");
gdvDailyReports.DataSource = ds;
gdvDailyReports.DataBind();
}
Stored Procedure
--=========================================================
-- CREATE BY :
-- CREATE DATE : <--/--/---->
-- MODIFY BY :
-- MODIFY DATE : <--/--/---->
-- DESCRIPTION :
--=========================================================
CREATE PROCEDURE sam_proc_MyProcedure
@Selection_TypeINT=0,
@EmpTypeINT=0,
@SalaryINT=0
AS
BEGIN
IF(@Selection_Type=1)
BEGIN
SELECT NAME, [ADDRESS] , MOBILE, PHONE FROM EmployeeMaster WHERE EmpType=@EmpType AND Salary <=@Salary
END
IF(@Selection_Type=2)
BEGIN
SELECT NAME, [ADDRESS] , MOBILE, PHONE FROM EmployeeMaster WHERE EmpType=@EmpType AND Salary >=@Salary
END
END
--=========================================================
Hope Your Problem Will Solve, Otherwise send me reply or Show me Your codding,
I'll try to solve your problem
Pankaj PandeyPosted May 22, 2013, 8:45 AM
It will better to read about sp_executesql and make query and use it .
thanks