none
Hi, i am trying to make registration form but i kept geting error: CS1513 } expected but i can figure out how to fix it. Thanks in advance! RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    namespace RegistrationFormsApp
    {
        public partial class Form1 : Form
        {
            string StrConnections = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\fortu\OneDrive\Documents\RegDB.mdf;Integrated Security=True;Connect Timeout=30";
            public Form1()
            {
                InitializeComponent();
                textPassword.MaxLength = 8;
            }
            private void SubmitButton_Click(object sender, EventArgs e)
            {
                 if (textUsername.Text == "" || textPassword.Text == "")
                 {
                     MessageBox.Show("Please fill the registration form!");
                 }
                 else
                 {
                     MessageBox.Show("Password don't match. Try again!");
                 }
                    SqlConnection sqlCons = new SqlConnection(StrConnections);
               
                    sqlCons.Open();
                    SqlCommand cmd = new SqlCommand("UserInforInsertor", sqlCons);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Last_Name", textLastName.Text.Trim());
                    cmd.Parameters.AddWithValue("@First_Name", textFirstName.Text.Trim());
                    cmd.Parameters.AddWithValue("@Contact", textContact.Text.Trim());
                    cmd.Parameters.AddWithValue("@Address", textAddress.Text.Trim());
                    cmd.Parameters.AddWithValue("@Username", textUsername.Text.Trim());
                    cmd.Parameters.AddWithValue("@Password", textPassword.Text.Trim());
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("The registration is completed!");
                    Clear();
            }
            private void Clear()
            {
                textLastName.Text = textFirstName.Text = textContact.Text = textAddress.Text = textPassword.Text = textConfirmPassword.Text = "";
            }
        } 
       
    }
    Friday, December 20, 2019 9:04 AM

Answers

  • The compiler is indicating you are missing a closing curly brace. I dumped your entire form into a project and did not get this error so it must be someplace else.

    Now if I remove a closing brace on the submit button click and compile we get this in the error list window which gives you the line number where the brace was expected. The other error is because of the missing brace.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, December 20, 2019 11:00 AM
    Moderator
  • Double click the compiler error in the Output or Error List window and it'll take you to the line where the compiler reported the error. Then using the IDE's brace matching to identify where you're missing the closing brace.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, December 20, 2019 2:53 PM
    Moderator

All replies

  • The compiler is indicating you are missing a closing curly brace. I dumped your entire form into a project and did not get this error so it must be someplace else.

    Now if I remove a closing brace on the submit button click and compile we get this in the error list window which gives you the line number where the brace was expected. The other error is because of the missing brace.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, December 20, 2019 11:00 AM
    Moderator
  • Double click the compiler error in the Output or Error List window and it'll take you to the line where the compiler reported the error. Then using the IDE's brace matching to identify where you're missing the closing brace.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, December 20, 2019 2:53 PM
    Moderator