vs2008中获取SQL数据库中数据失败
privatevoidcomboBox2_SelectedIndexChanged(objectsender,EventArgse){conn.myconnection....
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
conn.myconnection.Open();
string sql2 = string.Format("select SUM(money) from dbo.money where (month(riqi)='{0}' and zhuotaihao='{1}')", comboBox2.SelectedText.ToString(), comboBox1.Text.ToString());
SqlCommand mycommand2 = new SqlCommand(sql2, conn.myconnection);
SqlDataReader mydatareader2 = mycommand2.ExecuteReader();
if (mydatareader2.Read())
{
textBox2.Text = mydatareader2[0].ToString();
MessageBox.Show("11"); // 在实际运行中,这个“11”成功出现
conn.myconnection.Close();
}
conn.myconnection.Close();
}
dbo.money:
money zhuotaihao riqi
96 6 2016-05-03
textbox2 不显示内容
combbox1.selectedText=6 展开
{
conn.myconnection.Open();
string sql2 = string.Format("select SUM(money) from dbo.money where (month(riqi)='{0}' and zhuotaihao='{1}')", comboBox2.SelectedText.ToString(), comboBox1.Text.ToString());
SqlCommand mycommand2 = new SqlCommand(sql2, conn.myconnection);
SqlDataReader mydatareader2 = mycommand2.ExecuteReader();
if (mydatareader2.Read())
{
textBox2.Text = mydatareader2[0].ToString();
MessageBox.Show("11"); // 在实际运行中,这个“11”成功出现
conn.myconnection.Close();
}
conn.myconnection.Close();
}
dbo.money:
money zhuotaihao riqi
96 6 2016-05-03
textbox2 不显示内容
combbox1.selectedText=6 展开
展开全部
SQLSERVER认证模式:
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "Data Source=;Initial Catalog=;User Id=sa;Password=123456;";
sqlCon.Open();
windows认证模式:
Data Source=.;Initial Catalog=数据库;Integrated Security=True
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "Data Source=;Initial Catalog=;User Id=sa;Password=123456;";
sqlCon.Open();
windows认证模式:
Data Source=.;Initial Catalog=数据库;Integrated Security=True
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询