c# - 使用WFA接口(interface)插入数据时出现sqlException

标签 c# mysql asp.net crystal-reports windows-forms-designer

我正在使用 Visual Studio 和 MSSMS 中的 Windows 应用程序表单界面进行演示,将数据插入“crystaldb”本地数据库以创建 Crystal 报表。我检查并假设我引用的 sql 数据库中有正确的表,并且它肯定被称为“crystaldb”。我第一次编译成功插入了1行数据,但之后编译时抛出sql异常。

Here's the interface:

Interface for data insertion

Here's the code for the "Submit" and "Close" buttons and main function:

    private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=ZPCU0209\\SQLSERVERYANG;Initial Catalog=crystaldb;Integrated Security=True");
        con.Open();
        SqlCommand sc = new SqlCommand("Insert into cystaldb values('"+ textBox1.Text +"',"+ textBox2.Text +",'"+ textBox3.Text +"','"+ textBox4.Text +"','"+ textBox5.Text +"','"+ textBox6.Text +"','"+ textBox7.Text +"','"+ textBox8.Text +"','"+ textBox9.Text +"','"+ textBox10.Text +"',"+ textBox11.Text +");",con);
        int o= sc.ExecuteNonQuery();
        MessageBox.Show(o + " : Record has been inserted");
        con.Close();
    }
    public static void main(string[] args)
    {
        Application.Run(new Form1());
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

This is the database table setting:

enter image description here

Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll

Invalid object name 'cystaldb'.

有人可以帮我解决这个问题吗?

最佳答案

您在查询中拼写错误 crystaldb:

SqlCommand sc = new SqlCommand("Insert into **cystaldb** values(...));

您缺少 crystaldb 中的“r”。

关于c# - 使用WFA接口(interface)插入数据时出现sqlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42536129/

相关文章:

MySQL如何在这个例子中使用索引?

asp.net - asp :DropDownList width, 填充父级

html - 如何根据其内部文本(英语/阿拉伯语)设置正确的元素 css 方向(ltr/rtl)?

c# - 具有自动完成功能的文本框

php - 在 Codeigniter 中将旧的程序化 PHP 函数转换为模型- View - Controller (MVC)

mysql - 远程访问我的 Web 服务器上的 MySQL

c# - 使用 Emgu CV(或 OpenCV)进行运动跟踪

c# - 获取已删除的 DataGridView 行的单元格值

c# - 有没有办法在 Visual Studio 中不创建显式 EventHandler 委托(delegate)?

c# - 使用包装器类模拟 .NET 类