Contact Me

Nirav Prabtani

Mobile : +91 738 308 2188

Email : niravjprabtani@gmail.com

Nirav Prabtani

Wednesday, 16 July 2014

Insert , Update, Delete list of items in cookies.

Insert , Update, Delete list of items in cookies.


add values to cookies in C#

HttpCookie cookie = new HttpCookie("mybigcookie");
cookie.Values.Add("name", name);
cookie.Values.Add("address", address);

delete cookies item in C#

Response.Cookies["CoockieName"].Values["itemIndex"] = String.Empty;
 


How Can I Split A String In Vb.Net

How Can I Split A String In Vb.Net


  Dim FileName As String = Path.GetFileName("~/photos/consultant/images.jpeg")

How to use insertion and deletion of row using stored procedure.

How to use insertion and deletion of row using stored procedure.


try operational stored procedure.
You have to declare variable @operation with int datatype like as shown below,
Now you can execute perticular query with just passing @operation from backend.
 
You can put both query in one operation as you wish.
You can execute multiple operations with this query.... Smile | :) 

CREATE PROCEDURE SP_MyQuery
     @ItemCode VARCHAR(50)=''
    ,@ItemDescription VARCHAR(250)=''
    ,@ItemCategoryID INT=0
,@ItemID INT=0
,@operation int=0
AS
BEGIN
IF(@operation=1)
begin
--What ever you want to execute, insert query , update query , delete query, select query
end
ELSE IF(@operation-2)
BEGIN
--What ever you want to execute, insert query , update query , delete query, select query
END
END

Send Sms from ASP.NET using Full On Sms

Send Sms from ASP.NET using Full On Sms


1) HTML

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Send Sms</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Mobile No"></asp:Label>    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label>
        &nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="Send Sms"
            onclick="Button1_Click" />            
    </div>
    </form>
</body>
</html>


2) C#

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
 
public partial class _Default : System.Web.UI.Page
{
 
    string uid;
    string password;
    string message;
    string no;
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
   //This is the code of API for sending message.
    public void send()
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=fullonsms");
        HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
        System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = respStreamReader.ReadToEnd();
        respStreamReader.Close();
        myResp.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            uid = "";
            password = "";
            message = TextBox2.Text;
            no = TextBox1.Text;
            send();
            TextBox2.Text = "";
            TextBox1.Text = "";
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }



How to get Friday dates in a Month sql

How to get Friday dates in a Month


try this.. Smile | :) 

declare @DateFrom datetime,@DateTo datetime
set @DateFrom='23 Mar 2014'
set @DateTo='26 Jun 2014'
 
;WITH CTEQuery AS (
 SELECT CAST(@DateFrom AS DATETIME) AS dt
 UNION ALL
 SELECT DATEADD(dd, 1, dt)
  FROM CTEQuery s
  WHERE DATEADD(dd, 1, dt) <= CAST(@DateTo AS DATETIME)
  ),sampleData as(
select dt,datename(WEEKDAY,dt)as [DayName] from CTEQuery )
select * from sampleData where [DayName]='Friday'

you have to just pass @DateFrom and @DateTo from code behind and you will get all friday dates between there dates.. Smile | :)

How to set online image to Picturebox in windows form

Give URL to picturebox



pictureBox1.Load("http://www.dotnetperls.com/favicon.ico");

For more info:


Wednesday, 28 May 2014

SQL Get the last date of the month

Introduction

In this tip and trick i am going to write about how to get last day of a perticular month of passed date?

Background

We can get last day of a month by several manipulations and use of built in date functions of sql server.

Using the code

Here I have declared @InputDate DateTime variable to pass date then i have set @InputDate Manually you can pass it from codebehind ,then i have created small snippet for retrieving last day of passed date
declare @InputDate datetime
set @InputDate='06/26/2014' --MM/DD/YYYY Format
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@InputDate))),DATEADD(mm,1,@InputDate)),101) as ReturnedDate 
Here i have Convert date in MM/DD/YYYY format using
Convert(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@InputDate))),DATEADD(mm,1,@InputDate)),101)
here 101 return date in MM/DD/YYYY format you can convert it in different format for more information you can see this Article
We can create function to return last date of a month in this way
 CREATE FUNCTION [dbo].[func_LastDate](@Date DATETIME)
returns nvarchar(100)
AS
BEGIN
    DECLARE @ReturnedDate nvarchar(100)
    select @ReturnedDate=CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@Date))),DATEADD(mm,1,@Date)),103)

    return @ReturnedDate

END 
We can call this function in this way
 declare @Date varchar(100)
select @Date=  [dbo].[func_LastDate] (getdate())
print @Date 

History

Alternate version of SQL Get the last date of the month[^]