C# .NET - getting null values when retriving values from database

Asked By abinav shankar on 19-Jan-12 02:41 AM
I am getting an issue when fetching the values from database (i.e) when I am fetching the values using the Mysqldataadapter I am getting null values but when I close the solution and restart the application I get the values correctly this happens mostly when fetching the data from database not when inserting into the Db I am pasting my connection string details and the code with this pl tell me where I went worng
Calling the routine:
public string getManagerDetails(string strAssId)
    MySqlConnection strCon = new MySqlConnection(strConnection);
    MySqlCommand cmdMgrDetails = new MySqlCommand("sp_getManagerDetails", strCon);
    MySqlDataAdapter daMgrDetails = new MySqlDataAdapter(cmdMgrDetails);
    DataTable dtMgrDetails = new DataTable();
    cmdMgrDetails.Parameters.Add("@assoId", MySqlDbType.Int32).Value = Convert.ToInt32(strAssId.Trim());
    daMgrDetails.SelectCommand.CommandType = CommandType.StoredProcedure;
    if (dtMgrDetails.Rows.Count != null || dtMgrDetails.Rows.Count.ToString() != "")
      return dtMgrDetails.Rows[0]["associate_fname"].ToString();
      return "";
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_getManagerDetails`(In assoId integer)
select associate_fname from associate_details where associate_id=
(select manager_id from associate_details where associate_id=assoId);
connection strings:
<add name="Constr" connectionString="dataSource=localhost;Initial Catalog=kcube_intra;uid=root;password=kcubeserver"  providerName="MySql.Data.MySqlClient"/>

D Company replied to abinav shankar on 19-Jan-12 03:21 AM
Hello Abinav,

As suggested in yesterday post to use IsPostback, just try it in pageload and let use know if it is working

like this
page Load()
    if (!isPostBack)
    getManagerDetails(string strAssId)

Jitendra Faye replied to abinav shankar on 19-Jan-12 05:31 AM
Where you are calling your methos. call this method in page_load() event so it will display data on page load.