Thursday, 4 August 2011

how to pass particular column rows rows vise values to a procedure like EventId

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                 ds = obj.GetPartEventReportnew(Convert.ToInt32(dlstEventUsercount.Tables[0].Rows[i]["Event_Id"]), attendeeId, fromdate, todate);
            }

how to remove dropdownlist all rcods through java script

 document.getElementById("ctl00$ContentPlaceHolder1$G_drpGD_Type").length = 0;

Date Filtering on Store Procedure

Create procedure [dbo].[PMP_GetPartEventReportnew]  
@Event_Id int, 
@Attendee_Id int,
@Fromdate datetime,
@Todate datetime
AS               
Begin 
select distinct e.Event_Id,ex.Amount,s.State_initials,sim.SpendItem_Name 
from PMP_EventInformation e 
JOIN PMP_StateMaster s ON e.Event_State_Id = s.State_Id 
JOIN PMP_Expenses ex ON e.Event_Id = ex.Eventid 
JOIN PMP_AttendeeInformation ea ON ex.Attendeeid = ea.Attendee_Id 
JOIN PMP_SpendItemMaster sim ON ex.SpendItemid = sim.SpendItem_id  
where e.Event_Id = @Event_Id and ex.Attendeeid = @Attendee_Id  
and CONVERT(VARCHAR(50),ex.Date_Submitted,121) between CONVERT(VARCHAR(50),@Fromdate,121) and CONVERT(VARCHAR(50),@Todate,121)
Order By e.Event_Id 
end 

Thursday, 14 July 2011

Sql procedure declare variable and store query result to variable and chek condition if rowcount > 0 execute statement

Create procedure [dbo].[PMP_GetActivityType]
@Role AS VARCHAR(200)=''
as
begin
IF (UPPER(@Role) = UPPER('Vendors') OR UPPER(@Role) = UPPER('Vendor'))
BEGIN
DECLARE @Rule1 INT
SELECT @Rule1 = RuleId FROM PMP_BusinessRules WHERE RuleId = '11'
IF @@rowcount > 0
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
WHERE RuleId = '11' AND Status = 1
END
ELSE
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
WHERE Status = 1
END
END
ELSE

BEGIN
select Eventtype_Id,Type_Name as ActivityType
from PMP_EventType where Status=1
order by Type_Name
END
end

----------------------------------------------- 2 -------------------------------------------

Create PROCEDURE [dbo].[PMP_GetEventType]
(
@Eventtypeid INT=0,
@Role AS VARCHAR(200)=''
)
AS
BEGIN
IF (@Eventtypeid <> '0')
BEGIN
IF (UPPER(@Role) = UPPER('Vendors') OR UPPER(@Role) = UPPER('Vendor'))
BEGIN

DECLARE @Rule1 INT
SELECT @Rule1 = RuleId FROM PMP_BusinessRules WHERE RuleId = '11'
IF @@rowcount > 0
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
where RuleId = '11' AND Status = 1
END
ELSE
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
WHERE Status = 1
END
END
ELSE
BEGIN
SELECT Eventtype_Id, [Type_Name]
FROM PMP_EventType
WHERE Eventtype_Id = @Eventtypeid
AND Status = 1
Order by OrderID
END
END
ELSE
BEGIN

IF (UPPER(@Role) = UPPER('Vendors') OR UPPER(@Role) = UPPER('Vendor'))
BEGIN

DECLARE @Rule2 INT
SELECT @Rule2 = RuleId FROM PMP_BusinessRules WHERE RuleId = '11'
IF @@rowcount > 0
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
where RuleId = '11' AND Status = 1
END
ELSE
BEGIN
SELECT DISTINCT ET.Eventtype_Id, ET.Type_Name
FROM PMP_EventType AS ET LEFT OUTER JOIN PMP_BusinessRules AS BR ON ET.Eventtype_Id = BR.FromId
WHERE Status = 1
END
END
ELSE
BEGIN
SELECT Eventtype_Id, [Type_Name]
FROM PMP_EventType
WHERE Status = 1
Order by OrderID
END
END
END







Wednesday, 13 July 2011

microsoft oledb 4.0 server can not register on your local machine

go to Administrative tools IIS manager under that select Application Pool there is a option Advance setting
Select 32-bit =true

Friday, 8 July 2011

How to load dropdownlist(drpBusinessUnit)


How to load dropdownlist(drpBusinessUnit)

----------write code on aspx.cs file-----------------------------
private void A_LoadBusinessUnit()
{
try
{
drpBusinessUnit.DataSource = objdt.GetBusinessUnit();
drpBusinessUnit.DataValueField = "BusinessUnit_ID";

drpBusinessUnit.DataTextField = "BusinessUnit_Name";
drpBusinessUnit.DataBind();
//ddlproduct.Items.Insert(0, "-Select-");
System.Web.UI.WebControls.ListItem cmbItem;
cmbItem = new System.Web.UI.WebControls.ListItem("-Select-", "0");
drpBusinessUnit.Items.Insert(0, cmbItem);
}

------------------------------------------write code on class file

public SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["Constr"]);

public DataSet GetBusinessUnit()
{
DataSet dsGetProduct = new DataSet();
try
{
if (sqlconn.State == ConnectionState.Closed)
{
sqlconn.Open();
}

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "PMP_GetBusinessUnit";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlconn;
SqlDataAdapter sqlda = new SqlDataAdapter();
sqlda.SelectCommand = cmd;
sqlda.Fill(dsGetProduct);
}
catch (Exception ex)
{

}
finally
{
sqlconn.Close();
}
return dsGetProduct;
}

-------------------write procedure---------------------------------------------

create procedure [dbo].[PMP_GetBusinessUnit]
as
select BusinessUnit_ID, BusinessUnit_Name
from PMP_BusinessUnit

Thursday, 7 July 2011

file upload control by storing image on database as a binary image format

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="FileUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.IO" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>

<body>
<form id="form1" runat="server">
Product Name:
<asp:TextBox id="txtProductName" runat="server" />
<br />
Product Image:
<asp:FileUpload id="FileUpload1" runat="server" />
<asp:Button id="btnSave" runat="server" Text="Save Product" onclick="btnSave_Click" />
<br /><br />
<asp:Label id="lblMessage" runat="server" />
</form>

</body>
</html>


CREATE TABLE [dbo].[Products](
[ID] [int] NULL,
[ProductName] [nvarchar](100) NULL,
[ProductImage] [varbinary](max) NULL
) ON [PRIMARY]












protected void btnSave_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string productName = txtProductName.Text;
byte[] productImage = FileUpload1.FileBytes;

string constr = "Data Source=TECH-SWAPNILM\\SQLEXPRESS; Initial Catalog=master; Integrated Security=true";
string query = "INSERT INTO Products(ProductName, ProductImage) VALUES(@ProductName, @ProductImage)";

SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);

com.Parameters.Add("@ProductName", SqlDbType.NVarChar).Value = productName;
com.Parameters.Add("@ProductImage", SqlDbType.VarBinary).Value = productImage;
con.Open();
int result = com.ExecuteNonQuery();
con.Close();

if (result > 0)
{
lblMessage.Text = "Product Saved Successfully";
}
}
else
{
lblMessage.Text = "Please Select Product Image File";
}
}

}