Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataRow row = ds.Tables[0].Rows[0];
- string value = (string)row;
- int? value = 5;
- DataRow row = ds.Tables[0].Rows[0];
- string value = row as string;
- DataRow row = ds.Tables[0].Rows[0];
- string value;
- if (row["fooColumn"] == DBNull.Value)
- {
- value = string.Empty;
- }
- else
- {
- value = Convert.ToString(row["fooColumn"]);
- }
- return row["MyCol"] == DBNull.Value ? -99 : Convert.ToInt32(Row["MyCol"]);
- Object.ID = DataReader["ID"] == DBNull.Value ? -99 : Convert.ToInt32(DataReader["ID"]);
- Object.Name = DataReader["Name"] == DBNull.Value ? "None" : Convert.ToString(DataReader["Name"]);
- Object.Price = DataReader["Price"] == DBNull.Value ? 0.0 : Convert.ToFloat(DataReader["Price"]);
- string value = (
- from row in ds.Tables[0].Rows
- select row.Field<string>(0) ).FirstOrDefault();
- SELECT
- ISNULL(name,'') AS name
- ,ISNULL(age, 0) AS age
- FROM
- names
- // Or if (row["fooColumn"] == DBNull.Value)
- if (row.IsNull["fooColumn"])
- {
- // use a null for strings and a Nullable for value types
- // if it is a value type and null is invalid throw a
- // InvalidOperationException here with some descriptive text.
- // or dont check for null at all and let the cast exception below bubble
- value = null;
- }
- else
- {
- // do a direct cast here. dont use "as", "convert", "parse" or "tostring"
- // as all of these will swallow the case where is the incorect type.
- // (Unless it is a string in the DB and really do want to convert it)
- value = (string)row["fooColumn"];
- }
- if (row.IsNull["fooColumn"])
- {
- value = string.Empty();
- }
- {
- else
- {
- value = row["fooColumn"].ToString;
- }
- DataRow row = ds.Tables[0].Rows[0];
- string value;
- if (row["fooColumn"] == DBNull.Value)
- {
- value = string.Empty;
- }
- else
- {
- value = Convert.ToString(row["fooColumn"]);
- }
- DataRow row = ds.Tables[0].Rows[0];
- string value = row.ToString()
Add Comment
Please, Sign In to add comment