1

trying to retrieve some data from the database and put in into my form. the code goes

notificationList.Add(new notificationForm(
            (String)dataset.Tables["alertdetails"].Rows[0]["memberName"],
            (String)dataset.Tables["alertdetails"].Rows[0]["locationName"],
            (String)dataset.Tables["alertdetails"].Rows[0]["photo"],
            "",
            (String)dataset.Tables["alertdetails"].Rows[0]["memberid"], 
            "",
            "", x, y, alertId));

the arguments for my notificationForm is

public notificationForm(String name, String location, String imageExtension,
                        String alertType,String memberid,String date,String time,
                        int x,int y,String alertid)

the error goes

Unable to cast object of type 'System.Int32' to type 'System.String'.

on the line whereby i retrieve memberid. anyone know how to fix that? it works fine for memberName, locationName and photo though.

2 Answers 2

1
dataset.Tables["alertdetails"].Rows[0]["memberid"]

gives you the integer value, if the datatype of memberid in the database is int. Then, either add ToString() at the end or cast it to an int.

Example:

dataset.Tables["alertdetails"].Rows[0]["memberid"].ToString()
                      OR
Convert.ToInt32(dataset.Tables["alertdetails"].Rows[0]["memberid"]) 
Sign up to request clarification or add additional context in comments.

Comments

0

Cast it to an int (32bit integer), which is what the error message is telling you.

Check the type of 'memberid' column in the database table. Presumably it is an integer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.