Click here to Skip to main content
16,012,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
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:
C#
public string getManagerDetails(string strAssId)
    {
        MySqlConnection strCon = new MySqlConnection(strConnection);
        strCon.Open();
        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;
        daMgrDetails.Fill(dtMgrDetails);
        if (dtMgrDetails.Rows.Count != null || dtMgrDetails.Rows.Count.ToString() != "")
        {
            return dtMgrDetails.Rows[0]["associate_fname"].ToString();
        }
        else
        {
            return "";
        }
        strCon.Close();
    }

Routine:
C#
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_getManagerDetails`(In assoId integer)
BEGIN
select associate_fname from associate_details where associate_id=
(select manager_id from associate_details where associate_id=assoId);
END


connection strings:

C#
<add name="Constr" connectionString="dataSource=My_Server;Initial Catalog=MY_Database_Name;uid=My_User_Name;password=My_Password"  providerName="MySql.Data.MySqlClient"/>


[Edit] Don't put your real connection details onto public websites, Reiss
Posted
Updated 18-Jan-12 21:47pm
v3
Comments
BobJanova 19-Jan-12 6:49am    
There doesn't look to be anything wrong with that code. (Okay, overstatement, there are things wrong with it*, but it should work.) I suspect that you have a bug in the code that generates the IDs that are passed to this function.

*: there are a few things:
1: don't pass integer IDs around as strings
2: in C# you shouldn't use type prefixing on variable names
3: you should probably return null (or throw an exception) instead of empty if the lookup fails

1 solution

Make sure that this program does not give any error, i would request you to debug the code because i could not find any where you are executing the command.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900