SQL Server插入

The*_*Man 1 .net c# sql sql-server asp.net

我有一个简单的双字段表单,将其数据存储在数据库中.出于某种原因,它无法正常工作.我已经验证了连接字符串的工作原理,因为它在我制作的另一个项目中使用.

我没有包括第一个类的开头或它的页面加载.

码:

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string Name = txtName.Text;
        string Description = txtSpecial.Text;
        string method = string.Format(
            "INSERT INTO RbSpecials (Name,Description,Active) VALUES ('{0}','{1}','1')",
            Name,
            Description);
        RbConfiguration mySql = new RbConfiguration();
        try
        {
            mySql.Sql_Connection(method);
        }
        catch
        {

        }
    }
}

public class RbConfiguration
{
    string DbConnectionString = "System.Configuration.ConfigurationManager.ConnectionStrings['RBConnectionString'].ConnectionString";

    public void Sql_Connection(string queryString)
    {
        SqlConnection conn = new SqlConnection(DbConnectionString);
        SqlCommand cmd = new SqlCommand(queryString, conn);
        conn.Open();

        conn.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

Ada*_*lls 5

您永远不会执行您的SQL命令:

conn.Open(); 
cmd.ExecuteNonQuery(); 
conn.Close(); 
Run Code Online (Sandbox Code Playgroud)

你的连接字符串是错误的(抛弃双引号):

string DbConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["RBConnectionString"].ConnectionString;
Run Code Online (Sandbox Code Playgroud)