亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

找不到名為的列

找不到名為的列

C#
蠱毒傳說 2021-11-28 18:46:58
我有 2 個數據網格需要顯示 2 個表中的數據,我為每個數據網格使用了 2 個加載表來顯示數據。public diagnosechipcomplainprint(){    InitializeComponent();    load_table();}void load_table(){    string query = "Select HospitalRecordNo,concat(Patient_Fname, ' ', Patient_Mname, ' ',Patient_Lname) as 'Patient Name',Age,Gender,DateOfBirth,Email,PatientContact from patientinfo;";    MySqlConnection con = new MySqlConnection(connection);    MySqlCommand com = new MySqlCommand(query, con);    try    {        MySqlDataAdapter sd = new MySqlDataAdapter();        sd.SelectCommand = com;        DataTable dba = new DataTable();        sd.Fill(dba);        BindingSource bs = new BindingSource();        bs.DataSource = dba;        dataGridView1.DataSource = bs;        sd.Update(dba);    }    catch (Exception ex)    {        MessageBox.Show(ex.Message);    }}void load_table2(){    string query2 = "Select VisitNo, HospitalRecordNo, DateOfVisit from visit_details where HospitalRecordNo = '" + recordno.Text + "';";    MySqlConnection con = new MySqlConnection(connection);    MySqlCommand com = new MySqlCommand(query2, con);    try    {        MySqlDataAdapter sd = new MySqlDataAdapter();        sd.SelectCommand = com;        DataTable dba = new DataTable();        sd.Fill(dba);        BindingSource bs = new BindingSource();        bs.DataSource = dba;        dataGridView2.DataSource = bs;        sd.Update(dba);    }    catch (Exception ex)    {        MessageBox.Show(ex.Message);    }}當我在第一個數據網格上單擊單元格時,數據網格中的數據將顯示在標簽中,但是當我單擊第二個數據網格時,它顯示錯誤。這是我在 Cellclick 數據網格視圖 2 中使用的代碼。我希望你能幫助我。謝謝
查看完整描述

2 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

我發現第二個查詢DataGridView只包含 3 個列定義,實際上您需要 10 個列,如DataGridViewRow.Cells索引器中所述:


// only 3 columns returned in result set

string query2 = "Select VisitNo, HospitalRecordNo, DateOfVisit from visit_details where HospitalRecordNo = '" + recordno.Text + "';";

您應該提及DataGridViewRow.Cells查詢結果集中所需的所有列名,并使用參數化查詢來防止 SQL 注入:


string query2 = @"Select VisitNo, HospitalRecordNo, DateOfVisit, Nurse_on_duty, 

                  Temperature, Cardiac_Rate, Respiratory_Rate, Blood_Pressure, 

                  Weight, 02_Stat

                  from visit_details where HospitalRecordNo = @RecordNo";


// MySqlCommand parameter assignment

com.Parameters.AddWithValue("@RecordNo", recordno.Text);


查看完整回答
反對 回復 2021-11-28
?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

您在運行時收到錯誤,因為您的查詢未返回名為Nurse_on_duty其他一些列也發生了同樣的問題。

nurse.Text = row1.Cells["Nurse_on_duty"].Value.ToString();


查看完整回答
反對 回復 2021-11-28
  • 2 回答
  • 0 關注
  • 392 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號