here, i want to check only if the column Active is Yes, then get into the if loop. But it gives me an error “Cannot convert from string to int” for the last condition in if. What do you guys i can do. Thanks!!
if (ds != null && ds.Tables != null
&& ds.Tables.Count > 0
&& ds.Tables[0].Rows.Count > 0
&& ds.Tables[0].Columns[0].ColumnName["Status"] == "Y")
{
disableloc.DataSource = ds;
disableloc.DataBind();
}
else
{
ds = null;
disableloc.DataSource = ds;
disableloc.DataBind();
The stored procedure is SELECT ML.locationname,
rtrim(ML.address) + (CASE WHEN ML.Address2 IS NOT NULL THEN (” ” + rtrim(ML.Address2)) ELSE ”” END) + ” – ”+ ML.city + ”, ”+ ML.state as address,
ML.locationid,
ML.merchantid,
case when ML.active <> ”Y” then ”Deactive” else ”Active” end [Status],
(SELECT count() as retval
FROM merchant_statistics
WHERE type = ”merchant”
AND locationID= ML.LocationID
AND status = ”clicked”) as stat,
” ” as button,” ” as blank ,
dbo.GetCouponCountForLocations(@_merchantid,ML.locationID) couponCount,
MP.DomainName,
(SELECT Count() FROM Promotion WHERE LocationId = ML.locationid AND PostType = 1) AS jobs
FROM merchant_location ML , Merchant_Pages MP
WHERE MP.LocationID = ML.LocationID
AND ML.merchantid = @_merchantid Order By ‘
Your compilation error is caused because
ColumnNamereturns a String, and the only indexer String defines is an integer indexer that returns the character at the specified position.Assuming you are trying to access the value of the “Active” column for the first row:
ds.Tables[0].Columns[0].ColumnName["Active"] == "Y"should be
ds.Tables[0].Rows[0]["Active"] == "Y"