please tell me c# code i want to determine largest number in a column of sql server 2000 table and store it in a variable.
arsalanghouri
0
Newbie Poster
Recommended Answers
Jump to Postint myVariable = 0; using (SqlConnection sqlConn = new SqlConnection("connString")) { using (SqlCommand cmd = new SqlCommand(@"SELECT MAX(MyColumnName) FROM MyTable", sqlConn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { if (reader.GetValue(0) != DBNull.Value) myVariable = (int)reader[0]; } } } }
Jump to PostI hope you didnt use the exact code I pasted?!
You have to change the Sql query (to suit your dataBase design) and you have to use your connection string while creating a new reference of SqlConnection class.And one more thing: I boxes the retreived value to integer. …
All 6 Replies
Mitja Bonca
557
Nearly a Posting Maven
arsalanghouri
0
Newbie Poster
Mitja Bonca
557
Nearly a Posting Maven
arsalanghouri
0
Newbie Poster
arsalanghouri
0
Newbie Poster
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.