从列表框控件中选择一项(从数据库中获取数据)后,我试图向datagridview显示对应的数据。但是我陷入了我的字符串变量值是数据库中多个表的连接字符串的部分。但是,当我尝试对字符串使用单个数据库列时,尽管它运行良好。
下面的代码提供了所有详细信息。
当我尝试在此lstbox_doc_pat_opd.Items.Add(mysqlconstring.reader["hopdlog.licno"].ToString());
下的字符串“ selectdlst”中使用单个数据库列时,它会很好地工作,但是当使用lstbox_doc_pat_opd.Items.Add(mysqlconstring.reader["Doctors"].ToString());
时,由于是串联列,它将返回null。 。
private void lstbox_doc_pat_opd_SelectedIndexChanged(object sender, EventArgs e)
{
LOAD_REGISTERED_PAT_TO_TABLE();
}
private void LOAD_DOCTORS_IN_LISTBOX()
{
mysqlconstring.conn.Open();
string dtc = _datetime_pat_reg.Value.ToString("yyyy-MM-dd");
string query201 = "SELECT CONCAT(hpersonal.firstname, ' ', hpersonal.lastname) AS 'Doctors', hopdlog.licno AS 'License No.' FROM hopdlog INNER JOIN hprovider ON hprovider.licno=hopdlog.licno INNER JOIN hpersonal ON hpersonal.employeeid=hprovider.employeeid WHERE DATE(opddate) = @Datecurr GROUP BY hopdlog.licno ";
mysqlconstring.cmd = mysqlconstring.conn.CreateCommand();
mysqlconstring.cmd.CommandType = CommandType.Text;
mysqlconstring.cmd.CommandText = query201;
mysqlconstring.cmd.Parameters.AddWithValue("@Datecurr", dtc);
mysqlconstring.reader = mysqlconstring.cmd.ExecuteReader();
while (mysqlconstring.reader.Read())
{
lstbox_doc_pat_opd.Items.Add(mysqlconstring.reader["Doctors"].ToString());
}
mysqlconstring.conn.Close();
}
private void LOAD_REGISTERED_PAT_TO_TABLE()
{
mysqlconstring.conn.Open();
string dtc = _datetime_pat_reg.Value.ToString("yyyy-MM-dd");
string selectdlst = lstbox_doc_pat_opd.SelectedItem.ToString();
string query201A = "select CONCAT(hperson.patlast, ', ', hperson.patfirst, ' ',hperson.patmiddle) as 'Patient Name', hopdlog.hpercode as 'Hospital Number', hopdlog.tacode as 'Type of Service', hopdlog.tscode as 'Payment Type' from hopdlog INNER JOIN hperson ON hopdlog.hpercode=hperson.hpercode inner join hprovider ON hprovider.licno=hopdlog.licno inner join hpersonal ON hpersonal.employeeid=hprovider.employeeid where DATE(opddate) = @Datecurr AND hopdlog.licno ='" + selectdlst + "'";
mysqlconstring.cmd = mysqlconstring.conn.CreateCommand();
mysqlconstring.cmd.CommandType = CommandType.Text;
mysqlconstring.cmd.CommandText = query201A;
mysqlconstring.cmd.Parameters.AddWithValue("@Datecurr", dtc);
mysqlconstring.adapt.SelectCommand = mysqlconstring.cmd;
DataTable datble = new DataTable();
mysqlconstring.adapt.Fill(datble);
dgtable_doc_pat_opd.DataSource = datble;
mysqlconstring.conn.Close();
}