Reputation: 23
I'm having error with my code "Invalid Token 'String' in class, struct or interface member declaration" please help.
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;
}
}
I'm trying to just return the message string and grab that message once called. thank you!
Upvotes: 2
Views: 2833
Reputation: 50864
You can't return string
and have no return value (void
) at the same time. Since you want to return a value remove void
private string InsertRecords(TextBox textboxname, string qryname, string parametername) { }
Upvotes: 3