Click here to Skip to main content
15,886,560 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi guys! hi programmers and dvelopers.

I would like to ask about my project.

in my project i have two textbox such as text1 and text2

now the user will input a integer that will range the count

example the user inputted 1 in text1 and 5 for text2

therefore

it will go like this

1
2
3
4
5

maybe if i can display it with a label but more important is to make the numbers insert to the database.

to summarize when i input the range the system will count and the numbers will automatically be in the database.

thanks guys.

i really need some help here. please.

more power! have a great day! looking forward for your help. ;)
Posted
Updated 4-Dec-11 17:35pm
v3
Comments
D K N T H 4-Dec-11 20:59pm    
is this an assignment?
Ariel Riyo 4-Dec-11 21:17pm    
a project sir. thats one of the function
Manoj K Bhoir 4-Dec-11 23:39pm    
You want to insert 1,2,3,4,5 in same column or different columns?
Ariel Riyo 5-Dec-11 2:49am    
same columns sir but different rows.

An efficient way would be to create a stored procedure for this. Something like
SQL
CREATE PROCEDURE InsertNumbers @start int, @end int
AS
BEGIN
   DECLARE @counter int = @start;

   WHILE (@counter <= @end) BEGIN
      INSERT INTO YourTable (ColumnName) VALUES (@counter);
      SET @counter = @counter + 1;
   END;
END;
GO

And you can call it from client side using ExecuteNonQuery[^]
 
Share this answer
 
--Execute below script on your SQL

SQL
DECLARE @Start BIGINT 
Declare @END BIGINT 
SET @Start = 1
SET @END = 50
BEGIN

WITH mycte AS
(
SELECT @Start as id
UNION ALL
SELECT id + 1
FROM    mycte
WHERE  id + 1 < = @END
)
SELECT id
FROM mycte
OPTION (MAXRECURSION 0)
END
 
Share this answer
 
v2
You can use For Loop and write insert query in that.It may help you.
I hope you know basics of Ado.Net i.e how to connect with DataBase and all.
VB
Dim StartValue As Int32 = Val(TextBox1.Text)
Dim EndValue As Int32 = Val(TextBox2.Text)

For i As Int32 = StartValue To EndValue
Dim objCommand As OleDbCommand = New OleDbCommand 'Command Object
objCommand.Connection = Con     'Con is connection Object
objCommand.CommandText = "Insert into TableName (FieldName) Values(@FieldName)"
objCommand.SelectCommand.Parameters.AddWithValue("@FieldName", i)
   Try
       'Open your Connection before executiong the Query.
       objCommand.ExecuteNonQuery()
   Catch ex As Exception
       MessageBox.Show(ex.Message) 'Error Message if any
   End Try
objCommand = Nothing
Next

I hope it will help you. :)
 
Share this answer
 
Comments
Ariel Riyo 6-Dec-11 19:12pm    
Sir hello. thank you for your help. but i still have few questions. in the 1st @fieldname is the column of the table and the 2nd @fieldname is still the column or the textbox?

and sir i already set the connection and i open the connection before executenonquery but it still dont execute.
Manoj K Bhoir 7-Dec-11 2:14am    
Second field name is the same value you mentioned above as @FieldName ex :
objCommand.CommandText = "Insert into TableName (Name) Values(@Name)"
objCommand.SelectCommand.Parameters.AddWithValue("@Name", i)
Manoj K Bhoir 7-Dec-11 2:17am    
and also this is not a second field.This is first field in which you are passing the value which will pass in the actual query at the time of query execution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900