类,结构或接口成员声明中的令牌“字符串”无效

时间:2017-07-05 11:58:18

标签: c# asp.net

我的代码“类,结构或接口成员声明中的无效令牌'字符串'出错”请帮忙。

private void string InsertRecords(TextBox textboxname, string qryname, string parametername)
{
    string msg;

    if (textboxname.Text != "")
    {
        ConnString conn = new ConnString();
        string MyConn = conn.GetConn(); // Get Connection String

        using (SqlConnection sqlconn = new SqlConnection(MyConn))
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = qryname;
                cmd.Parameters.AddWithValue("@" + parametername, SqlDbType.VarChar).Value = textboxname.Text;
                cmd.Connection = sqlconn;
                sqlconn.Open();
                cmd.ExecuteNonQuery();

                msg = $"<strong>Record Successfully Added!</strong>";
                return msg;
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2146232060)
                {
                    msg = $"<strong>Record already exist in the database!</strong>";
                    return msg;
                }
                else
                {
                    msg = $"<strong>Error Message: {ex.HResult}</strong>";
                    return msg;
                }
            }
        }
    }
    else
    {
        msg = $"<strong>Please complete required fields</strong>";
        return msg;
    }
}

我正在尝试返回消息字符串并在调用后抓取该消息。谢谢!

1 个答案:

答案 0 :(得分:1)

您无法同时返回string且没有返回值(void)。由于您要返回值,请删除void

private string InsertRecords(TextBox textboxname, string qryname, string parametername) { }