我想将数据插入我名为" Flujo_Efectivo"的数据库中,在桌子上" Entrada_Datos"在Visual Studio Community 2017上使用C#。该程序应该在按下按钮时保存数据。这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to save changes?", "Confirmation", MessageBoxButtons.OKCancel) ==
DialogResult.OK)
{
con = new SqlConnection(connectionString: @"Data Source = ACER\SQLEXPRESS2016; Initial Catalog = Flujo_Efectivo; Integrated Security = True");
con.Open();
cmd = new SqlCommand(cmdText: "INSERT INTO Entrada_Datos(Description,Quantity (Gs.),Quantity (USD)) VALUES (@Description,@Quantity (Gs.),@Quantity (USD))", connection: con);
cmd.Parameters.AddWithValue(parameterName: "@Description", value: textBox1.Text);
cmd.Parameters.AddWithValue(parameterName: "@Quantity (Gs.)", value: textBox2.Text);
cmd.Parameters.AddWithValue(parameterName: "@Quantity (USD)", value: textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show(text: "The changes have been saved", caption: "Notification");
}
}
但是,出现以下错误:
" system.data.sqlclient.sqlexception:')附近的语法不正确'"
我检查了每一个')'在我的查询中,我无法找到任何可能导致此类内容的内容。
提前谢谢
答案 0 :(得分:5)
您的SqlParameter
名称中不能包含空格或字符。并且在[]
INSERT INTO Entrada_Datos(Description,[Quantity (Gs.)],[Quantity (USD)]) VALUES (@Description,@QuantityGs,@QuantityUsd)
然后根据您分配值的位置重新命名它们:
cmd.Parameters.AddWithValue(parameterName: "@Description", value: textBox1.Text);
cmd.Parameters.AddWithValue(parameterName: "@QuantityGs", value: textBox2.Text);
cmd.Parameters.AddWithValue(parameterName: "@QuantityUsd", value: textBox3.Text);
答案 1 :(得分:0)
试试这样。
[from-internal]
exten => _X.,1,NoOP()
same => n,MixMonitor(${DialMonitorFile}.wav)
same => n,Dial(PJSIP/${EXTEN}@TRUNK_100-1234-5678,30)