IEnumerable "<"invention">" invention = from i in DataContext.invention where i.Sharable == true select i
Tuesday, 24 January 2012
Wednesday, 11 January 2012
Get-Checked-Repeater-Items-Extension-Method.aspx
http://www.objectreference.net/post/Get-Checked-Repeater-Items-Extension-Method.aspx
Friday, 6 January 2012
Binding Installed fonts in dropdownlist using LINQ
Namespace
using System.Drawing.Text;
Here is markup:
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">
using System.Drawing.Text;
Here is markup:
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">
<asp:ListItem>--- Please select font ---</asp:ListItem>
</asp:DropDownList>
Paste code bellow and put on your page load event.
C#
protected void Page_Load(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InstalledFontCollection instedFontColl = new InstalledFontCollection();
DropDownList1.DataSource = from font in instedFontColl.Families
select font.Name;
DropDownList1.DataBind();
}
}
linq-to-sql-part-6-retrieving-data
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
Thursday, 5 January 2012
Get Last Date And First Date Of The Month, Using C#
DateTime firstDay= new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
int DaysinMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)-1;
DateTime lastDay = firstDay.AddDays(DaysinMonth);
Tuesday, 3 January 2012
Check QueryString Empty or Null
if (Request.QueryString["[ID]"] != "" && Request.QueryString["[ID]"] != null)
{
//if (Request.QueryString["ID"].ToString() != null)
//{
LoadData(" AND SRNO = " + Request.QueryString["ID"].ToString() + "");
}
else
{
LoadData(string.Empty);
}
Sunday, 1 January 2012
SQl Search StoredProcedure
SQl Search StoredProcedure on columns FirstName,LastName,EmailID
Create procedure SearchCustomers ( @firstname varchar(50), @LastName varchar(50), @EmailId varchar(50) ) As Begin declare @SearchString varchar(1000) declare @BuildQuery varchar(50) Set @SearchString = 'Select * From Customers' if(@firstname <> '') Begin set @BuildQuery = ' FirstName like ''%' + @firstname + '%''' End if(@Lastname<>'') Begin IF(@BuildQuery<>'') set @BuildQuery = @BuildQuery + ' and LastName like ''%'+ @LastName +'%''' Else set @BuildQuery = @BuildQuery + ' LastName like ''%'+ @LastName +'%''' END if(@EmailId<>'') Begin if(@BuildQuery<>'') set @BuildQuery = @BuildQuery +' and EmailId like ''%'+ @EmailId +'%''' Else set @BuildQuery = @BuildQuery +' EmailId like ''%'+ @EmailId +'%''' end IF(@BuildQuery<>'') Begin Set @SearchString = @SearchString + ' where' + @BuildQuery End Exec(@SearchString) END
Use IN sql query Stored Procedure & retrieve data
ALTER PROCEDURE dbo.StoredProcedure2
@userid varchar(500)
AS
BEGIN
SET NOCOUNT ON
DECLARE @SQL varchar(600)
SET @SQL =
'SELECT USER_NAME, FIRST_NAME, PASSWORD, LAST_NAME, MIDDLE_NAME, SRNO FROM USER_MAS
WHERE SRNO IN (' + @userid + ')'
EXEC(@SQL)
END
protected void BtnSpIn_Click(object sender, EventArgs e)
{
SqlDB objDB = new SqlDB();
objDB.Prepare("StoredProcedure2", CType.StoredProcedure);
objDB.AddCmdParameter("@userid", DType.Varchar,"1,2", ParaDirection.In, false);
DataTable objDT = new DataTable();
objDT = objDB.ExecuteCommandDataReturn();
}
How to give a DataTable Name When returning Dataset From a StoreProcedure
public DataSet ExecuteCommandDataSetReturn()
{
try
{
OpenCon();
DataSet objDS = new DataSet();
cmd.CommandTimeout = 0;
cmd.Transaction = SqlTr;
SqlDataAdapter objDA = new SqlDataAdapter(cmd);
objDA.Fill(objDS);
return objDS;
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlDB objDB = new SqlDB();
objDB.Prepare("StoredProcedure1", CType.StoredProcedure);
DataSet ds = new DataSet();
ds = objDB.ExecuteCommandDataSetReturn();
ds.Tables[0].TableName = "TotalUser";
ds.Tables[1].TableName = "TotalComp";
Label1.Text = ds.Tables["TotalUser"].Rows[0]["totaluser"].ToString();
Label2.Text = ds.Tables["TotalComp"].Rows[0]["totalcomp"].ToString();
}
Multiple select statements in a stored procedure sql server 2005,2008
Yeah its possible..what we need is to specify the multiple select statements in store procedure..there is lots of way to fetch data. here i m using dataset to fetch all select statement...
ALTER PROCEDURE dbo.MultiSelect
AS
SELECT count(1) as totaluser FROM USER_MAS;
/* SET NOCOUNT ON */
SELECT count(1) as totalcomp FROM COMPANY_MASTER
RETURN
ALTER PROCEDURE dbo.MultiSelect
AS
SELECT count(1) as totaluser FROM USER_MAS;
/* SET NOCOUNT ON */
SELECT count(1) as totalcomp FROM COMPANY_MASTER
RETURN
private void GetMultiSelect() { using (SqlConnection con = new SqlConnection("ConnectionString")) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandText = "MultiSelect"; cmd.CommandType = CommandType.StoredProcedure; //dataset object to get all select statement results DataSet ds = new DataSet(); //sql dataadoptor to fill dataset using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { //here all select statements are fill in dataset object adp.Fill(ds); //now u can fetch each and every select statement by providing table index in dataset foreach (DataTable dt in ds.Tables) { //select statement result in dt.. } //or instead of loop u can specify the index ds.Tables[0]; // first select statement result ds.Tables[1]; // second select statement result } } } }
Subscribe to:
Posts (Atom)