hello

Monday, 22 October 2012

How Call StoredProcedure in c# Directly

Query = "exec spname '" + txtUserName.Text + "', '" + txtPassword.Text + "','" + ddlinsti.SelectedValue + "'";

How Call StoredProcedure in c#


        con = new SqlConnection("Data Source=122;Initial Catalog=test;Integrated Security=True");
        con.Open();
        cmd = new SqlCommand("GetLoginDetail", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = txtUserName.Text;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword.Text;
        cmd.Parameters.Add("@inst_id", SqlDbType.VarChar).Value = ddlinsti.SelectedValue;

        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();

Parameteris Query in c#

SqlCommand comm = new SqlCommand("INSERT INTO desg VALUES (@txtsno, @txtdesg, @txtbasic)", connection);

your_db.Open();
try {
    comm.Parameters.AddWithValue("@txtsno", txtsno.Text.Trim());
    comm.Parameters.AddWithValue("@txtdesg", txtdesg.Text.Trim());
    comm.Parameters.AddWithValue("@txtbasic", txtbasic.Text.Trim());
    comm.ExecuteNonQuery();
    comm.Dispose();
    comm = null;
}
catch(Exception ex)
{
    throw new Exception(ex.ToString(), ex);
}
finally
{
    your_db.Close();
}

Thursday, 18 October 2012

how send more than one query string

Response.Redirect("Default2.aspx?UserId="+txtUserId.Text+"&UserName="+txtUserName.Text);

Monday, 27 August 2012

row number and rank in sql server

select top 100 RANK() over(order by cust_po_no) as pono, * from dbo.tbl_cust_po_mst



select top 100 Row_number() over(order by cust_po_no) as pono, * from dbo.tbl_cust_po_mst

Thursday, 23 August 2012

MODULEL WISE REPORT STORE PROCEDURE

create proc [dbo].[Issue_Log_App_Pie]
as
begin
declare
@NonSAP numeric(8,2)declare @SAP numeric(8,2)declare @LMDM numeric(8,2)declare @Total numeric(8,2)create table #AppPie(App Varchar(50),Ticket Numeric(8,2))set @NonSAP =(SELECT count(*) as TOTAL_ISSUE from showissuelog where Application_Type_Id=2GROUP BY APPLICATION_TYPE) set @SAP=(SELECT count(*) as TOTAL_ISSUE from showissuelog where Application_Type_Id=1 and Application_id not in (3)GROUP BY APPLICATION_TYPE)set @LMDM=(SELECT count(*) as TOTAL_ISSUE from showissuelog where Application_Type_Id=1 and Application_id in (3)GROUP BY APPLICATION_TYPE)set @Total=(@NonSAP+@SAP+@LMDM)set @NonSAP=(@NonSAP/@Total)*100set @SAP=(@SAP/@Total)*100set @LMDM=(@LMDM/@Total)*100insert into #AppPie values ('Non SAP',@NonSAP)insert into #AppPie values ('SAP',@SAP)insert into #AppPie values ('LMDM',@LMDM)select * from #AppPieend

Monday, 13 August 2012

working with data grid in asp.net c#

<asp:DataGrid ID="DgList" runat="server" AutoGenerateColumns="false" OnItemCommand="DgList_ItemCommand"
OnSelectedIndexChanged="DgList_SelectedIndexChanged"><Columns><asp:BoundColumn DataField="Emp_id" Visible="false"></asp:BoundColumn><asp:BoundColumn DataField="Emp_Name" HeaderText="Emp Name"></asp:BoundColumn><asp:BoundColumn DataField="Dept_Desc" HeaderText="Dept Name"></asp:BoundColumn><asp:BoundColumn DataField="Salary" HeaderText="Salary"></asp:BoundColumn><asp:ButtonColumn CommandName="edit" HeaderText="Edit" Text="Edit"></asp:ButtonColumn><asp:ButtonColumn CommandName="del" HeaderText="Delete" Text="Delete"></asp:ButtonColumn></Columns></asp:DataGrid>
.cs
protected void DgList_SelectedIndexChanged(object sender, EventArgs e){
}

protected void DgList_ItemCommand(object source, DataGridCommandEventArgs e){

string id = e.Item.Cells[0].Text;
if (e.CommandName == "edit"){
Response.Redirect(
"EditEmp.aspx?q=" + id);}

if (e.CommandName == "del"){
Delete(id);
}
}