Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i work that my code just like:
SqlConnection con2 = new SqlConnection(con);
string str2 = string.Format("select top 1 tel from account where polish=N'پرداخت شد' And tag='1' ORDER BY NewId() ");
SqlCommand cmd2 = new SqlCommand(str2, con2);
con2.Open();
int i = Convert.ToInt32(cmd2.ExecuteScalar());
SqlConnection con3 = new SqlConnection(con);
string str3 = string.Format("select top 1 day_send from account where tel='{0}' ORDER BY NewId() ",i.ToString());
SqlCommand cmd3 = new SqlCommand(str3, con3);
con3.Open();
string j = Convert.ToString(cmd3.ExecuteScalar());
int k= int.Parse(j) * 30;
SqlConnection con14 = new SqlConnection(con);
string str14 = string.Format("select Bank from account where tel='{0}' and day_send='{1}'"
,i,j);
SqlCommand cmd14 = new SqlCommand(str14, con14);
con14.Open();
string i5 = Convert.ToString(cmd14.ExecuteScalar());
SqlConnection con4 = new SqlConnection(con);
string str4 =string.Format("select Count(DISTINCT message) from accounting where flag='0' and mobile='{0}' And Bank='{1}' "
,i.ToString(),i5.ToString());
SqlCommand cmd4 = new SqlCommand(str4,con4);
con4.Open();
int i1 = Convert.ToInt32(cmd4.ExecuteScalar());

work always in the web because in my code have a random selection and it must work ever in the web.
a mean I don,t know what do this for this problem please help me?
Posted
Updated 14-Apr-12 20:51pm
v2
Comments
Reza Ahmadi 15-Apr-12 2:36am    
I think the above code will work fine in a web-application as it doesn't have a special win-based code. What do you mean by "a random selection"?
Herman<T>.Instance 16-Apr-12 9:20am    
the order by newID() results in a random result

1 solution

All that appears to do is generate a (hopefully) random number in a very inefficient way.
There are two much easier ways to do it: via SQL or C# directly.
SQL:
SQL
SELECT CAST(RAND() * 100 AS INT) AS [RandomNumber]
Returns a random number between 0 and 99
C#:
C#
Random rand = new Random(); // Define at class level
...
int i = rand.Next(0, 100);
Returns a random number between 0 and 99
 
Share this answer
 

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