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();
}
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();
}
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!