简体   繁体   English

如何在c#中的控制台中显示数据库值

[英]how to display database value in console in c#

How to display the unitfunction value from mysql database and my query is below ,i don't know its right or wrong.如何显示mysql数据库中的unitfunction值,我的查询如下,我不知道它是对还是错。 Help me out.帮帮我。

 string fundev = "select unitfunctioncode from channels where channel_no = " + Channelid;
                    MySqlCommand getfun = new MySqlCommand(fundev, Connection1);
                    Console.WriteLine(getfun);

MAKE ENTITY CONTEXT FIRST: YourEntity db= new YourEntity();首先创建ENTITY CONTEXT :YourEntity db= new YourEntity(); LINQ:林克:

Console.Write(db.channels.Where(x=>x.channel_no == Channelid).Select(y=>y.unitfunctioncode));

This is modal first approach create modal from database and call this linq in controller这是模态第一种方法从数据库创建模态并在控制器中调用此linq

I'm not sure about the specifics of MySqlCommand, but I would expect to see an execute on your getfun object.我不确定 MySqlCommand 的具体细节,但我希望在您的 getfun 对象上看到execute

I would do something like this:我会做这样的事情:

MySqlDataReader rdr = getfun.ExecuteReader();
while (rdr.Read())
{
    Console.WriteLine(rdr[0]);
}
rdr.Close(); 

This takes into account multiple rows returned.这考虑了返回的多行。 You can omit the while loop if you're sure you will have a single row returned.如果您确定将返回单行,则可以省略 while 循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM