How to convert string to int?
in data table i want to validate one row.of the row have less than or equal zero value to validate it.how to do it.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Midhun TpRank #388 · 6.5K reputationPosted Sep 25, 2016, 4:21 AM EDT
Do you need to validate a row or column?
You can convert to int as below-
Convert.ToInt32(dt.Rows[0]["colname"].ToString())>0
Krishna Rajput SinghRank #605 · 4K reputationPosted Sep 25, 2016, 4:04 AM EDT
Delpin Susai RajRank #53 · 29.5K reputationPosted Sep 25, 2016, 5:38 AM EDT
Pradeep ShetRank #595 · 4K reputationPosted Sep 25, 2016, 6:26 AM EDT
RajaRank #1,035 · 1.9K reputationPosted Sep 25, 2016, 8:23 PM EDT
Midhun T P
Delpin Susai Raj
Pradeep Shet
Krishna Rajput Singh
Kishore ChowdaryRank #172 · 13.9K reputationPosted Sep 27, 2016, 7:19 AM EDT
Rajeev KumarRank #1,334 · 1.3K reputationPosted Mar 16, 2023, 5:54 AM EDT
Convert.ToInt32(dt.Rows[0]["columnname"].ToString())>0
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 16, 2023, 10:48 AM EDT
You can validate a row in a DataTable by iterating over the columns of the row and checking if any column's value is less than or equal to zero.
// Assuming dt is the DataTable containing the row to be validated DataRow row = dt.Rows[0]; // Get the first row foreach (DataColumn col in dt.Columns) { if (row[col] is int value && value <= 0) { // Value in column is less than or equal to zero // You can throw an exception, show an error message or handle it in some other way // For example: throw new Exception($"Value in column '{col.ColumnName}' is less than or equal to zero."); } }Tuhin PaulRank #7 · 71.9K reputationPosted Mar 16, 2023, 10:49 AM EDT
The first row of the DataTable
dt, iterates over its columns and checks if the value in any column is less than or equal to zero. If such a value is found, it throws an exception with an appropriate error message.