[英]No value given to one or more parameters
So I input some data into textbox then I click this button 所以我在文本框中输入一些数据,然后单击此按钮
private void button2_Click(object sender, EventArgs e)
{
command.Connection = connect;
if (idkaryawantxt.Text != "")
{
string q = "UPDATE tableAbsensi SET Absen_keluar =('" + (DateTime.Now.ToString("hh:mm")) + "') WHERE ID ='" + idkaryawantxt.Text.ToString() + "' AND Tanggal ='" + (DateTime.Now.ToString("MM-dd-yyyy")) +"'";
dosomething(q);
}
this.Close();
}
Then it says 然后说
No value given to one or more parameters
没有为一个或多个参数赋值
The table looked like this : 该表如下所示:
Check not only if idkaryawantxt
is empty but also if it is not null: 不仅检查
idkaryawantxt
是否为空,还要检查其是否不为null:
if (string.IsNullOrEmpty(idkaryawantxt.Text))
{
var currentDateTime = DateTime.Now;
string q = "UPDATE tableAbsensi SET Absen_keluar ='"
+ currentDateTime.ToString("hh:mm") + "' WHERE ID ='"
+ idkaryawantxt.Text + "' AND Tanggal ='"
+ currentDateTime.ToString("MM-dd-yyyy") +"'";
dosomething(q);
}
Secondly the brackets here (DateTime.Now.ToString("hh:mm"))
and here (DateTime.Now.ToString("MM-dd-yyyy"))
are not needed. 其次,这里不需要括号
(DateTime.Now.ToString("hh:mm"))
和这里(DateTime.Now.ToString("MM-dd-yyyy"))
。
You do not need to convert idkaryawantxt.Text
to string ( idkaryawantxt.Text.ToString()
), as it is already a string. 您不需要将
idkaryawantxt.Text
转换为字符串( idkaryawantxt.Text.ToString()
),因为它已经是字符串。
You do not need brackets here SET Absen_keluar =('"
and here "') WHERE ID ='"
. 您在这里不需要方括号
SET Absen_keluar =('"
,在这里"') WHERE ID ='"
。
What is more it might be useful to set the DateTime.Now
to a variable instead of calling it twice, because in some exceptional cases it could give you two different values. 更重要的是,将
DateTime.Now
设置为变量而不是两次调用可能是有用的,因为在某些特殊情况下,它可以给您两个不同的值。
And finally: avoid creating your queries in the way you did in this case. 最后:避免以这种情况下的方式创建查询。 It is not an elegant way of creating queries + it is not secured against SQL injections.
这不是创建查询的一种优雅方式,并且无法防止SQL注入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.