Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:07:35+00:00 2026-05-20T05:07:35+00:00

I made a stored procedure called usp_insertempdata that inserts data into the database table

  • 0

I made a stored procedure called “usp_insertempdata” that inserts data into the database table called “Employee”, so i executed it and when i save data i brings an exception:
“The ConnectionString property has not been initialized.
Any help please!
here is my code

    SqlConnection _SqlConnection = new SqlConnection ( );
string strConnectionString = "";
SqlCommand cmd = new SqlCommand ( );

strConnectionString = @"Server='bisweb\bisweb';Database=x_kgabo;Trusted_Connection=true;";

Int32 rowsAffected;

List<object> lstParams = new List<object> ( );

cmd.Parameters.Add ( new SqlParameter ( "@vchEmployeeNo", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchEmployeeNo" ].Value = txtEmployeeNumber.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchSurname", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchSurname" ].Value = txtSurname.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchFirstName", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchFirstName" ].Value = txtFirstName.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchPosition", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchPosition" ].Value = txtPosition.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchIdNumber", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchIdNumber" ].Value = txtIdNumber.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchGender", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchGender" ].Value = drpdwnGender.SelectedItem.Value;
cmd.Parameters.Add ( new SqlParameter ( "@vchRace", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchRace" ].Value = drpdwnRace.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchEmail", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchEmail" ].Value = txtEmail.Text;
cmd.Parameters.Add ( new SqlParameter ( "@iBranchNo", SqlDbType.VarChar ) );
cmd.Parameters [ "@iBranchNo" ].Value = txtBranchNo.Text;
cmd.Parameters.Add ( new SqlParameter ( "@bHasMentor", SqlDbType.VarChar ) );
cmd.Parameters [ "@bHasMentor" ].Value = drpdwnMentor.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchMentorName", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchMentorName" ].Value = txtMentorName.Text;
cmd.Parameters.Add ( new SqlParameter ( "@vchMentorStaffNo", SqlDbType.VarChar ) );
cmd.Parameters [ "@vchMentorStaffNo" ].Value = txtMentorStaffNo.Text;
cmd.Parameters.Add ( new SqlParameter ( "@dtMentorDate", SqlDbType.VarChar ) );
cmd.Parameters [ "@dtMentorDate" ].Value = calMentorDate.SelectedDate;

cmd.CommandText = "usp_insertempdata";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = _SqlConnection;

_SqlConnection.Open ( );

rowsAffected = cmd.ExecuteNonQuery ( );

_SqlConnection.Close ( );

try
{
    _SqlConnection.ConnectionString = strConnectionString;
    _SqlConnection.Open ( );

}
catch ( Exception ex )
{
    //throw  ex;
    messagefunctions ( );
    lblError.Text = "There was a problem inserting a record into the database, please consult with systems administrators " + ex.Message.ToString ( );
}
finally
{
    if ( _SqlConnection != null )
        _SqlConnection.Close ( );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:07:35+00:00Added an answer on May 20, 2026 at 5:07 am

    The problems seems to be that you are assigning the connection string after you called ExecuteNonQuery and after your first call to Open. The second call is nonsense.
    The correct sequence would be:

    cmd.CommandType = CommandType.StoredProcedure;
    _SqlConnection.ConnectionString = strConnectionString;
    cmd.Connection = _SqlConnection;
    
    try
    {
        _SqlConnection.Open ( );
    
        rowsAffected = cmd.ExecuteNonQuery ( );
    
        _SqlConnection.Close ( );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our development policy dictates that all database accesses are made via stored procedures, and
I have created a method that can be called using a stored procedure name
I want to make a Stored procedure which is made recursive The database has
Okay so I made some changes to a stored procedure that we have, and
I made that one column id GridView is lookup from stored procedure. Stored procedure
I made a stored procedure which has the following parameter : @UserName Would that
I have a stored procedure that loops through a table and it may insert
I'm attempting to use context.Database to execute a stored proc that inserts a record
Using MS SQL Server .I have made a Stored Procedure named SP_Get_CallsLogged . I
I have a trigger that stores changes made in a separate table when a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.