算不了。通过SQL查询从db访问? [英] Count no. Of visit from db by SQL query?

查看:66
本文介绍了算不了。通过SQL查询从db访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要完全没有。访问过的患者。

i将以下代码用c#作为:

 OleDbCommand vst = new OleDbCommand(select_get(*)from old_patient where Contact_no = @Contact_no GROUP BY Contact_no,cn); 
vst.Parameters.Add(new OleDbParameter(@ Contact_no,txtsno.Text));

//将值存储在rec变量中。
int rec =(int)vst.ExecuteNonQuery();
lbldtr.Text = rec.ToString();





txtsno是文本框;

lbldtr是我希望显示或打印答案的标签。


$ t $ bxtsno文本框中的b $ b有联系号码。所以,我希望得到特别的联系。访问。



提前谢谢



我尝试了什么:



 OleDbCommand vst = new OleDbCommand(从old_patient中选择count(*),其中Contact_no = @ Contact_no GROUP BY Contact_no,cn); 
vst.Parameters.Add(new OleDbParameter(@ Contact_no,txtsno.Text));

//将值存储在rec变量中。
int rec =(int)vst.ExecuteNonQuery();
lbldtr.Text = rec.ToString();

解决方案

您可能忘记在问题中写下您的问题了。

查看你的代码,它有以下错误

1.查询似乎不正确

  select  count(*)来自 old_patient 其中 Contact_no = @Contact_no  GROUP   BY  Contact_no 



应该be-

 选择 count(*)来自 old_patient 其中 Contact_no = @ Contact_no 



2.您应该使用ExecuteScalar而不是ExecuteNonQuery

  int  rec =( int )vst.ExecuteNonQuery( ); 



它应该是 -

  int  rec =(< span class =code-keyword> int )vst.ExecuteScalar(); 



这是详细阅读的详细文章 -

ExecuteReader ExecuteScalar和ExecuteNonQuery之间的区别 [ ^ ]



希望,它有帮助:)

如果您发现更多困难,请告诉我。


使用 ExecuteScalar [ ^ ]

ExecuteNonQuery 将返回受影响的行数,而不是您想要返回的实际值。



  int  rec =( INT )vst.ExecuteScalar(); 


i want to total no. of visited patient.
i make following code in c# as:

OleDbCommand vst = new OleDbCommand("select count(*) from old_patient where Contact_no=@Contact_no GROUP BY Contact_no", cn);
                        vst.Parameters.Add(new OleDbParameter("@Contact_no", txtsno.Text));

                        //  store value in rec variable.
                        int rec = (int)vst.ExecuteNonQuery();
                        lbldtr.Text = rec.ToString();



txtsno is textbox;
lbldtr is label where i want to show or print answer.

in txtsno textbox have contact no. so , i want to get particular contact no. visit.

thank u in advance

What I have tried:

OleDbCommand vst = new OleDbCommand("select count(*) from old_patient where Contact_no=@Contact_no GROUP BY Contact_no", cn);
                        vst.Parameters.Add(new OleDbParameter("@Contact_no", txtsno.Text));

                        //  store value in rec variable.
                        int rec = (int)vst.ExecuteNonQuery();
                        lbldtr.Text = rec.ToString();

解决方案

You probably have forgotten to write your problem in the question.
Looking at your code, it has following mistakes
1. Query seems to be incorrect

select count(*) from old_patient where Contact_no=@Contact_no GROUP BY Contact_no


It should be-

select count(*) from old_patient where Contact_no=@Contact_no


2. You should use ExecuteScalar instead of ExecuteNonQuery

int rec = (int)vst.ExecuteNonQuery();


it should be-

int rec = (int)vst.ExecuteScalar();


Here is a detailed article for detailed reading-
Difference between ExecuteReader ExecuteScalar and ExecuteNonQuery[^]

Hope, it helps :)
If you find further difficulties, please let me know.


use ExecuteScalar [^]
ExecuteNonQuery will return the number of rows affected, not the actual value which you want to return.

int rec = (int)vst.ExecuteScalar();


这篇关于算不了。通过SQL查询从db访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆