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 6113989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:55:19+00:00 2026-05-23T14:55:19+00:00

StringBuilder sb = new StringBuilder(); sb.Append(DECLARE @ControlPaneliD int); sb.Append( SET @ControlPaneliD=(SELECT ControlPanelID); sb.Append( FROM

  • 0
      StringBuilder sb = new StringBuilder();
    sb.Append("DECLARE @ControlPaneliD int");
    sb.Append(" SET @ControlPaneliD=(SELECT ControlPanelID");
    sb.Append(" FROM ControlPanelID");
    sb.Append(" WHERE Name=@Name)");

    sb.Append("DECLARE @UserName UniqueIdentifier");
    sb.Append(" SET @UserName=(SELECT Name");
    sb.Append(" FROM UsersID");
    sb.Append(" WHERE UsersID=@UserID)");

    sb.Append("INSERT INTO dbo.CP_Comments (ControlPanelID,Comments,Commentator)");
    sb.Append(" VALUES(@ControlPaneliD,@Comment,@UserName)");
    MembershipUser CurrentUser = Membership.GetUser();
    Guid id = (Guid)CurrentUser.ProviderUserKey;

    string myConnectionString = AllQuestionsPresented.connectionString;
    using (SqlConnection conn = new SqlConnection(AllQuestionsPresented.connectionString))
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
        cmd.Parameters.Add("UserID", SqlDbType.UniqueIdentifier).Value = id;
        cmd.Parameters.Add("Comment", SqlDbType.NVarChar).Value = TextBox1.Text;
        cmd.Parameters.Add("Name", SqlDbType.NVarChar).Value = name; //string variable from my code
        cmd.ExecuteNonQuery();

    }

I am trying to do two select statements, put their results in their variables and insert their variables plus another variable into another insert statement..

I am not sure if I am doing it right, I would appreciate your help if you gave me some advice and some criticism on what I composed

  • 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-23T14:55:20+00:00Added an answer on May 23, 2026 at 2:55 pm

    Your method looks OK but it is recommended that you use stored procedure instead of passing query

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

StringBuilder sb = new StringBuilder(); sb.Append( string.Format({0} |{1} , Name, Value) ); Display.Text =
Have following String built SQL query: StringBuilder querySelect = new StringBuilder(select * from messages
How do you append a new line(\n\r) character in StringBuilder ?
StringBuilder query = new StringBuilder(); query.Append(CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) );
SqlDataReader myreader; myreader = cmmd.ExecuteReader(); StringBuilder sb = new StringBuilder(); sb.Append(<b>Vaccine</b>&nbsp;&nbsp;&nbsp;<b> Vaccination Date</b>&nbsp;&nbsp;&nbsp;<b> Vaccination
StringBuilder scriptFunction = new StringBuilder(); scriptFunction.Append(<script language='javascript'>); scriptFunction.Append(alert('de')); scriptFunction.Append(</script>); ClientScript.RegisterStartupScript(GetType(), alert, scriptFunction.ToString()); This is
Public Function MethodOne(ByVal s As String) As String Dim sb As New StringBuilder() sb.Append(s)
I have this code: StringBuilder command = new StringBuilder(ffmpeg -ac 1 -i ); command.append(videoFile.getPath());
Dim sb As StringBuilder = New StringBuilder() sb.Append(<script language=javascript>) sb.Append( function SetValueInBody() {) sb.Append(
I have this code to create an ATOM feed Dim xmlResult As New StringBuilder

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.