Hi @fahimahmed,
I have made a small snippet for you.
Try this..
SQL
--SeriesRecords_SaveRecord 1,100,4
CREATE PROCEDURE SeriesRecords_SaveRecord
@MinRange INT
,@MaxRange INT
,@ZeroBeforeNumber INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @NumberValue VARCHAR(50)
SET @ZeroBeforeNumber = @ZeroBeforeNumber + 1
WHILE(@MinRange<=@MaxRange)
BEGIN
SELECT @NumberValue = RIGHT(REPLICATE('0',@ZeroBeforeNumber)
+ CAST(@MinRange AS VARCHAR(10)),@ZeroBeforeNumber)
SET @MinRange = @MinRange + 1
INSERT INTO Series_Records
SELECT @NumberValue,@NumberValue
END
END
GO
Html
<div>
Min Range:<asp:TextBox ID="txtMinRange" runat="server" /><br />
Max Range:
<asp:TextBox ID="txtMaxRange" runat="server"></asp:TextBox>
<br />
<asp:Button Text="Save" runat="server" OnClick="Save" />
</div>
C# Code
protected void Save(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
int zeroCount = 0;
foreach (char item in (this.txtMinRange.Text.Trim()).ToCharArray())
{
if (item == 48)
{
zeroCount++;
}
}
SqlCommand cmd = new SqlCommand("SeriesRecords_SaveRecord", con);
cmd.Parameters.AddWithValue("@MinRange", int.Parse(this.txtMinRange.Text.Trim()));
cmd.Parameters.AddWithValue("@MaxRange", int.Parse(this.txtMaxRange.Text.Trim()));
cmd.Parameters.AddWithValue("@ZeroBeforeNumber", zeroCount);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
Namespaces
using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;