从数据库检索值时获取空值 [英] getting null values when retriving values from database
问题描述
嗨
从Mysqldataadapter中获取值时,从数据库中获取值时出现问题,但是当我关闭解决方案并重新启动应用程序时,我正确地获取了值,这通常在获取数据时发生从数据库而不是从数据库中插入DB时,我粘贴了连接字符串的详细信息,并且此pl的代码告诉我磨损的地方
调用例程:
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:
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:
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:
<add name="Constr" connectionString="dataSource=My_Server;Initial Catalog=MY_Database_Name;uid=My_User_Name;password=My_Password" providerName="MySql.Data.MySqlClient"/>
不要将您的真实连接详细信息放到公共网站上,Reiss
Don''t put your real connection details onto public websites, Reiss
推荐答案
请确保该程序没有出现任何错误,我会要求您调试代码,因为找不到执行命令的任何位置.
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.
这篇关于从数据库检索值时获取空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!