繁体   English   中英

SQL Server错误,“关键字不受支持”的“数据源”

[英]SQL Server Error, 'Keyword not supported 'datasource'

我目前正在尝试将一些值插入到数据源中,然后使用DataList控件将它们显示在另一页上。 但是,经过一些测试和实验,我发现该错误从一开始就出现了。

这是我绑定到按钮上的代码。

protected void btnSend_Click(object sender, EventArgs e)
    {
    Page.Validate("vld2");
    SendMail();
    lblMsgSend.Visible = true;
    txtPhone.Text = "";
    txtEmail.Text = "";
    txtName.Text = "";
    txtComment.Text = "";

    //SQL Server Database
    SqlConnection conn; //manages connection to database
    SqlCommand cmd; //manages the SQL statements
    string strInsert; //SQL INSERT Statement
        try
        {
            //create a connection object
            conn = new SqlConnection("DataSource=localhost\\sqlexpress;" +
                                     "Initial Catalog=RionServer;" +
                                     "Integrated Security=True;");
            //Build the SQL INSERT Document
            strInsert = "INSERT INTO CommentsAdmin (Name,Phone,Email,Comments)"
                + "VALUES(@Name,@Phone,@Email,@Comments);";
            //associate the INSERT statement with the connection
            cmd = new SqlCommand(strInsert, conn);
            //TELL the SqlCommand WHERE to get the data from
            cmd.Parameters.AddWithValue("Name", txtName);
            cmd.Parameters.AddWithValue("Phone", txtPhone);
            cmd.Parameters.AddWithValue("Email", txtEmail);
            cmd.Parameters.AddWithValue("Comments", txtComment);
            //open the connection
            cmd.Connection.Open();
            //run the SQL statement
            cmd.ExecuteNonQuery();
            //close connection
            cmd.Connection.Close();
            //display status message on the webpage
            lblMsgSend.Text = "Thank you for the comment! Please hit the 'Return to Main Page' to return to the Main Page!";
        }
        catch (Exception ex)
        {
            lblMsgSend.Text = ex.Message;
        }
    }

这是我网页的图像及其显示的错误。

SQL Server错误。不支持关键字“数据源”

如果您需要其他信息,请告诉我。

提前致谢。

在您的连接字符串中,它应该是“数据源”,而不是“数据源”。 只需添加一个空格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM