Hi all! Im totaly new in programing, so i need some help if someone can help me...
Im programing in VS 2005, C# language and using MS SQL Server 2005 .
So, after i fill my table with 10 records, i would like to use First In First Out ordering process. The problem is, that after the DELETE statement, when i trigger the INSERT statement, the record is not placed in the last row, but replaces the row that i've deleted...
I have 2 columes...count er and data
For example:
counter data
1 a
2 a
3 a
4 a
.
.
.
DELETE FROM table1 WHERE counter = '" + c + "' "
INSERT INTO table1 values ('" + c + "','c')"
it does
1 c
2 a
3 a
4 a
.
.
.
This is how it use to be:
counter data
2 a
3 a
4 a
.
.
.
9 a
10 a
1 c
My code:
[PHP]static void Main()
{
int i;
int c;
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection(
"Data Source=ADVMBRPP ;Initial Catalog=proba;I ntegrated Security=SSPI") ;
SqlDataReader rdr = null;
try
{
// Open the connection
conn.Open();
for (i = 1; i <= 10; i++)
{
// prepare command string
string insertString = @"
INSERT INTO table1 values ('"+i+"','a') ";
// 1. Instantiate a new command with a query and connection
SqlCommand cmd = new SqlCommand(inse rtString, conn);
// 2. Call ExecuteNonQuery to send command
cmd.ExecuteNonQ uery();
}
i--;
if (i == 10)
{
for (c = 1; c < 2 ; c++ )
{
// prepare command string
string deleteString = @"DELETE FROM table1 WHERE counter = '" + c + "' ";
SqlCommand cmd2 = new SqlCommand(dele teString,conn);
string insertString = @"INSERT INTO table1 values ('" + c + "','c')";
SqlCommand cmd3 = new SqlCommand(inse rtString, conn);
cmd2.ExecuteNon Query();
cmd3.ExecuteNon Query();
}
}
}
finally
{
// Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
[/PHP]
Any help would be appreciated and sorry for my bad english
Tnx
Andrew
Im programing in VS 2005, C# language and using MS SQL Server 2005 .
So, after i fill my table with 10 records, i would like to use First In First Out ordering process. The problem is, that after the DELETE statement, when i trigger the INSERT statement, the record is not placed in the last row, but replaces the row that i've deleted...
I have 2 columes...count er and data
For example:
counter data
1 a
2 a
3 a
4 a
.
.
.
DELETE FROM table1 WHERE counter = '" + c + "' "
INSERT INTO table1 values ('" + c + "','c')"
it does
1 c
2 a
3 a
4 a
.
.
.
This is how it use to be:
counter data
2 a
3 a
4 a
.
.
.
9 a
10 a
1 c
My code:
[PHP]static void Main()
{
int i;
int c;
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection(
"Data Source=ADVMBRPP ;Initial Catalog=proba;I ntegrated Security=SSPI") ;
SqlDataReader rdr = null;
try
{
// Open the connection
conn.Open();
for (i = 1; i <= 10; i++)
{
// prepare command string
string insertString = @"
INSERT INTO table1 values ('"+i+"','a') ";
// 1. Instantiate a new command with a query and connection
SqlCommand cmd = new SqlCommand(inse rtString, conn);
// 2. Call ExecuteNonQuery to send command
cmd.ExecuteNonQ uery();
}
i--;
if (i == 10)
{
for (c = 1; c < 2 ; c++ )
{
// prepare command string
string deleteString = @"DELETE FROM table1 WHERE counter = '" + c + "' ";
SqlCommand cmd2 = new SqlCommand(dele teString,conn);
string insertString = @"INSERT INTO table1 values ('" + c + "','c')";
SqlCommand cmd3 = new SqlCommand(inse rtString, conn);
cmd2.ExecuteNon Query();
cmd3.ExecuteNon Query();
}
}
}
finally
{
// Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
[/PHP]
Any help would be appreciated and sorry for my bad english
Tnx
Andrew
Comment