我试图插入我的C#应用程序中的SQL数据库.
我已经阅读了一些文档,并提出了我认为可行的方法.实际上,当用户输入他们的数据并按下提交按钮时,应用会暂停一段时间,然后给我一个"SqlException",并提到一些无法连接的事情.
我不确定我是否正确使用了连接字符串,所以我正在寻求帮助.
这些是我用来构建查询并建立连接的方法:
private void btn_Submit_Click(object sender, EventArgs e)
{
if (isValidData())
{
//MessageBox.Show("Valid", "All Entries Were Valid!");
//CONVERT FORM VALUES AND STORE IN VARIABLES TO SEND TO MYSQL QUERY
DateTime saleTime = saleDatePicker.Value;
Decimal price = Convert.ToDecimal(txt_Price.Text);
string customerName = txt_CustomerName.Text;
string customerPhone = txt_CustomerPhone.Text;
string description = rTxt_Description.Text;
//Build Query string
string query = "INSERT into SALES VALUES ('" + saleTime + "','" +
price + "','" + customerName + "','" + customerPhone + "','" +
description …Run Code Online (Sandbox Code Playgroud)