我想从我的数据表中获取有两列的值。名称和订单时间。我想在文本框中从时间中减去相应的值。我指的是使用以下代码的数据表值。我可以在
中得到结果string First = (mydatabaseDataSet.Tables[0].Rows[1][2].ToString());
MessageBox.Show(First);
但为什么我无法与以下代码进行比较和获取价值。 感谢
private void comboBox_suburb_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox_suburb.SelectedValue!=null)
if (comboBox_suburb.SelectedItem.ToString() == mydatabaseDataSet.Tables[0].Rows[i][j].ToString())
{
int timetosub = Convert.ToInt32(mydatabaseDataSet.Tables[0].Rows[i][j + 1]);
totaltime = bdtime + timetosub;
tmpk = totaltime;
time3 = time2.AddMinutes(-tmpk);
textBox_ordertostart.Text = time3.ToString("hh:mm tt");
}
}
答案 0 :(得分:0)
好的,所以我解决了这个问题。 感谢您的反馈!
private void comboBox_suburb_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\WoolsValley\documents\visual studio 2015\Projects\WindowsFormsApplication17\WindowsFormsApplication17\mydatabase.mdf; Integrated Security = True");
con.Open();
int i = comboBox_suburb.SelectedIndex;
int j = 1;
comboBox_suburb.ValueMember = mydatabaseDataSet.Tables[0].Columns[1].ToString();
if (comboBox_suburb.SelectedItem.ToString() == (mydatabaseDataSet.Tables[0].Rows[i][j].ToString())) ;
{
int timetosub = Convert.ToInt32(mydatabaseDataSet.Tables[0].Rows[i][j + 1]);
totaltime = bdtime + timetosub;
tmpk = totaltime;
time3 = time2.AddMinutes(-tmpk);
textBox_ordertostart.Text = time3.ToString("hh:mm tt");
}
}