0

現在、いくつかの値をデータソースに挿入し、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;
        }
    }

これが私のウェブページの画像とそれが表示するエラーです。

SQLServerエラー。 キーワード「データソース」はサポートされていません

追加情報が必要な場合はお知らせください。

前もって感謝します。

4

1 に答える 1

8

接続文字列では、「DataSource」ではなく「Data Source」にする必要があります。スペースを追加するだけです。

于 2013-02-18T02:44:56.720 に答える