如何从c#server2008的c#windows窗体中查找表中使用的相同值的次数 [英] how to find how many times a same value has been used in table from c# windows forms with sql server2008

查看:116
本文介绍了如何从c#server2008的c#windows窗体中查找表中使用的相同值的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的名字是vishal我想知道如何在c#server2008的c#windows窗体中找到相同值(组合框项/文本)的次数。



我的表格中有一个名为: cboDialyzerID 的组合框: frmCleaning

给定下面是我的表的结构名为: reprocessor 在sql server2008中

ColumnName DataType AllowNulls

reprocessor_id Int否(自动增加主键)

start_date datetime是

end_date datetime是

row_upd_date datetime是

dialysis_date datetime是

bundle_vol Int是

去除fectant Int是

technician_id Int Yes

user_id Int Yes

dialyzer_id nvarchar(30)是

prime_volume Int Yes



下面给出的是我的c#格式代码: frmCleaning 我从中将值插入到SQL中的表 reprocessor server2008。

hi my name is vishal i was wondering how to find how many times a same value(combobox item/text) has been used in same table from c# windows forms with sql server2008.

I have a combobox named:cboDialyzerID in my form named:frmCleaning.
Given below is structure of my table named:reprocessor in sql server2008
ColumnName DataType AllowNulls
reprocessor_id Int No(since auto-increment primary key)
start_date datetime Yes
end_date datetime Yes
row_upd_date datetime Yes
dialysis_date datetime Yes
bundle_vol Int Yes
disinfectant Int Yes
technician_id Int Yes
user_id Int Yes
dialyzer_id nvarchar(30) Yes
prime_volume Int Yes

Given below is my c# code of form:frmCleaning from which i insert values into table reprocessor in sql server2008.

private void btnCreate_Click(object sender, EventArgs e)
        {
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            int autoGenId = -1;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd = new SqlCommand("Insert into reprocessor(start_date,end_date,dialyzer_id,dialysis_date,prime_volume,bundle_vol,disinfectant,technician_id,row_upd_date,user_id,errorCode)" + "Values(@start_date,@end_date,@dialyzer_id,@dialysis_date,@prime_volume,@bundle_vol,@disinfectant,@technician_id,GetDate(),@user_id,@errorCode); Select @autoGenId=SCOPE_IDENTITY();", conn);
            cmd.Parameters.AddWithValue("@start_date", dtSTime.Value);
            cmd.Parameters.AddWithValue("@end_date", dtETime.Value);
            cmd.Parameters.AddWithValue("@dialyzer_id", cboDialyzerID.Text);
            cmd.Parameters.AddWithValue("@dialysis_date", dtDDate.Value);
            cmd.Parameters.AddWithValue("@prime_volume", txtPrimeVol.Text);
            cmd.Parameters.AddWithValue("@bundle_vol", txtBVol.Text);
            cmd.Parameters.AddWithValue("@disinfectant", txtDisInfectant.Text);
            cmd.Parameters.AddWithValue("@technician_id",cboTechnician.SelectedValue);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.Parameters.AddWithValue("@errorCode", 0);
            cmd.Parameters.Add("@autoGenId", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            autoGenId = Convert.ToInt32(cmd.Parameters["@autoGenId"].Value);
            ((MDIParent1)this.MdiParent).updateUserActivities(autoGenId, 7,cboDialyzerID.Text.ToString());
MessageBox.Show("Reprocessing data was successfully added", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
}



我通过c#中的以下代码在 frmCleaning 中填充名为: cboDialyzerID 的组合框:


I populate my combobox named:cboDialyzerID in frmCleaning through following code in c#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DRRS_CSharp
{
    public partial class frmCleaning : Form
    {
public frmCleaning()
        {
InitializeComponent();
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
string DialyzerPull = ("Select dialyserID from dialyser where deleted_status=0 and closed_status=0");
            SqlCommand dcd = new SqlCommand(DialyzerPull);
            dcd.Connection = conn;
            dcd.CommandType = CommandType.Text;
            SqlDataReader cr = dcd.ExecuteReader();
            while (cr.Read())
            {
                DialyzerPull = cr[0].ToString();
                cboDialyzerID.Items.Add(DialyzerPull);
            }
            cr.Close();
}





我想要的是找到并知道字段中每个值的次数 dialyzer_id nvarchar(30):sql server2008中的 reprocessor 已在同一个表中使用: reprocessor 来自c#windows窗体用sql server2008。有人可以帮我吗?任何帮助/指导解决这个问题将不胜感激。任何人都可以帮忙!



What i want is to find and know how many times each value in field dialyzer_id of data-type:nvarchar(30) in table:reprocessor in sql server2008 has been used in same table:reprocessor from c# windows forms with sql server2008. Can anyone help me please? Any help/guidance in solving of this problem would be greatly appreciated.! Can anybody help please!

推荐答案

SELECT dialyzer_id, COUNT(dialyzer_id) FROM reprocessor GROUP BY dialyzer_id


您可以编写一个SQL查询来执行此操作。



使用名为'count'的SQL聚合函数和'Group By'子句。



http://msdn.microsoft.com/en-us/library/ms177673.aspx [ ^ ]
You can write a SQL Query that will do this.

Use a SQL aggregation function called 'count', and the 'Group By' clause.

http://msdn.microsoft.com/en-us/library/ms177673.aspx[^]

这篇关于如何从c#server2008的c#windows窗体中查找表中使用的相同值的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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