c#我想用两个textbox中的任意一个textbox在数据库中查询然后显示在另一个里我下面的代码需要怎么修改 100
stringcondtr="server=localhost;UserId=root;password=zyz;Database=cd";MySqlConnectionm...
string condtr = "server=localhost;User Id=root;password=zyz;Database=cd";
MySqlConnection mycon = new MySqlConnection(condtr);
mycon.Open();
MySqlCommand mycmd = new MySqlCommand("select * from cd1 where 英文='" + textBox1.Text + "'", mycon);
MySqlDataReader mydr = mycmd.ExecuteReader();
if (mydr.HasRows)
{
while (mydr.Read())
{
textBox2.Text = mydr["英文"] + "\n";
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.CreateCells(dataGridView1, new object[] { "查询", textBox1.Text, textBox2.Text });
dataGridView1.Rows.Add(dgvr);
}
Console.ReadLine();
mycon.Close();
}
else
{
MessageBox.Show("词典暂无此单词");
} 展开
MySqlConnection mycon = new MySqlConnection(condtr);
mycon.Open();
MySqlCommand mycmd = new MySqlCommand("select * from cd1 where 英文='" + textBox1.Text + "'", mycon);
MySqlDataReader mydr = mycmd.ExecuteReader();
if (mydr.HasRows)
{
while (mydr.Read())
{
textBox2.Text = mydr["英文"] + "\n";
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.CreateCells(dataGridView1, new object[] { "查询", textBox1.Text, textBox2.Text });
dataGridView1.Rows.Add(dgvr);
}
Console.ReadLine();
mycon.Close();
}
else
{
MessageBox.Show("词典暂无此单词");
} 展开
1个回答
展开全部
string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName=toolName"; 第二个toolName应该是个参数吧,应该 string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName='"+toolName+"'"; 然后你的year1+month1 你看下结果是什么,是日期的格式吗?应该不是吧。 格式相同才能比较撒。 如果2008-1-1和20081 怎么比较。
追问
我现在有另一个问题 你有时间吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询