***HELP*** Return String from SQL Statment & Increment this String

Last post 10-18-2008 2:18 AM by bhadhra. 3 replies.

Sort Posts:

  • ***HELP*** Return String from SQL Statment & Increment this String

    10-08-2008, 12:09 AM
    • Member
      point Member
    • taketothesky
    • Member since 10-08-2008, 4:03 AM
    • Posts 2

    How can I get one value from a select statement and put it into a string and then modify it in that same method?  What I want to do is get the last branch number and increment by 1 and return that value.  It will be a string value so I will need to get help B002.  So I would want it to assign B003 as my return value.  Also, I have to use the OleDbConnection.

        public string GetNewBranchID()
        {
            String sql = "SELECT last.branchNo FROM Branch ORDER BY branchNo";

            OleDbConnection connection = new OleDbConnection(GetConnString());
            OleDbCommand cmd = new OleDbCommand(sql, connection);

           OleDbConnection oConn = new OleDbConnection(sConn);
          oConn.Open();

          OleDbCommand oCmd = new OleDbCommand(sSQL, oConn);
          OleDbDataReader oReader = oCmd.ExecuteReader();

          while(oReader.Read())
          {
            Console.WriteLine("{0}",
              oReader["branchNo"]);
          }

        }

  • Re: ***HELP*** Return String from SQL Statment & Increment this String

    10-08-2008, 1:17 AM
    • Member
      479 point Member
    • J K
    • Member since 09-11-2008, 7:17 AM
    • Posts 116

    Hi,
    You can do this with simple srting manipulations in the same function
    Regards,
    JK

  • Re: ***HELP*** Return String from SQL Statment & Increment this String

    10-08-2008, 1:46 AM
    • Member
      point Member
    • taketothesky
    • Member since 10-08-2008, 4:03 AM
    • Posts 2

     Can you give me examples?  Of how to input into a string variable from a SQL statement and then how to manipulate a string variable via the substring?  I can't find any examples out there.  I can't find any examples on putting the value from the SQL statement into a string.  And I have been trying to slice my value with the sql substr but I get a error Syntax error (missing operator) in query expression 'substr(TOP 1 branchNo,2,3)'.

     So far nothing is going well for me tonight and I have spent hours trying to look this up!

     I really appreciate any help you can offer with examples!!

  • Re: ***HELP*** Return String from SQL Statment & Increment this String

    10-18-2008, 2:18 AM
    • Member
      10 point Member
    • bhadhra
    • Member since 08-11-2008, 7:23 AM
    • Posts 8

      public string GetNewBranchID()
        {
            String sql = "SELECT max(last.branchNo FROM Branch ORDER BY branchNo";

            OleDbConnection connection = new OleDbConnection(GetConnString());
            OleDbCommand cmd = new OleDbCommand(sql, connection);

           OleDbConnection oConn = new OleDbConnection(sConn);
          oConn.Open();

          OleDbCommand oCmd = new OleDbCommand(sSQL, oConn);
          OleDbDataReader oReader = oCmd.ExecuteReader();

          while(oReader.Read())
          {
          int branchnor=int.parse(oReader[branchno].tostring()) +1;


    string str=branchno.tostring();

         }

        }

Page 1 of 1 (4 items)