SQL Server错误,“关键字,不支持”数据源“ [英] SQL Server Error, 'Keyword not supported 'datasource'

查看:353
本文介绍了SQL Server错误,“关键字,不支持”数据源“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在努力一些值插入到数据源,然后使用DataList控件在另一页上显示它们。然而,一些测试和试验之后,我发现这个错误来自一开始。

I'm currently trying to INSERT some values into a datasource, then display them on another page using the DataList control. However, after some testing and experimentation, I've found that the error comes from the very beginning.

下面是code我已绑定到我的按钮。

Here is the code I have bound to my button.

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;
        }
    }

下面是我的网页上的图像,并显示错误。

Here is the image of my webpage and the error it displays.

请让我知道如果你需要更多的信息。

Please let me know if you need additional information.

先谢谢了。

推荐答案

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

In your connection string, it should be "Data Source", not "DataSource". Just add a space.

这篇关于SQL Server错误,“关键字,不支持”数据源“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆