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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:54:12+00:00 2026-05-27T04:54:12+00:00

My scenario is this. i have a telephone table that needs to be updated

  • 0

My scenario is this. i have a telephone table that needs to be updated (incase they need to change the existing one for the client) or delete (incase they wish to delete the existing number) or insert (incase the field is empty n a new no is inserted).
i already have two stored procedures which adds a new telephone and updates an existing one. whose parameters are:

 EXECUTE @RC = [CUSTOMER_test].[dbo].[uspAddClientTel] 
   @ClientID
  ,@TelNo
  ,@TelTypeID
  ,@DetailsTypeID
  ,@SortNo
  ,@ResultTelID OUTPUT 

EXECUTE @RC = [CUSTOMER_test].[dbo].[uspUpdateClientTel] 
   @TelID
  ,@TelNo
  ,@TelTypeID
  ,@DetailsTypeID
  ,@SortNo
  ,@ResultTelID OUTPUT
GO

a part of the query in form view

  (SELECT TOP 1 F.tel_no FROM TELEPHONE as F where F.tel_type_id = 3 AND F.client_id = @id ORDER BY sort_no ) AS fax, 
(SELECT TOP 1 T.tel_no from TELEPHONE as T where T.tel_type_id = 1 OR T.tel_type_id = 2 AND T.client_id = @id ORDER BY sort_no) AS telephone, 
(SELECT TOP 1 F.tel_id FROM TELEPHONE as F where F.tel_type_id = 3 AND F.client_id = @id ORDER BY sort_no ) AS faxid , 
(SELECT TOP 1 T.tel_id from TELEPHONE as T where T.tel_type_id = 1 OR T.tel_type_id = 2 AND T.client_id = @id ORDER BY sort_no) AS telephoneid ,
CLIENT_ADDRESS.client_address_id

  FROM ORGANIZATION AS O INNER JOIN CLIENT ON O.client_id = CLIENT.client_id
    LEFT OUTER JOIN CLIENT_ADDRESS ON  CLIENT.client_id = CLIENT_ADDRESS.client_id
 WHERE (CLIENT.client_id = @id)"

so i have the telephone (as landline/mobile ) and the fax along with their IDs , if they already exist in the DB.

Now i need to create a function which takes in the arguments and thereby decides which sp to use depending on the arguments passed to it.
I’m completely lost here. any help on how to go about this function will be much appreciated. even links to tutorials will help!
thanks again!

p.s
before trying the function i did something like this , but its not consistent

protected void FrmClient_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
    string TelTypeID;
    string ResultTelID1 = "";

    int intClientID = (int)e.Keys[0];
    string strTelID = (string)e.OldValues["telephoneid"];
    string strFaxID = (string)e.OldValues["faxid"];


     SqlConnection conTel = new SqlConnection();
    conTel.ConnectionString = Convert.ToString(ConfigurationManager.ConnectionStrings["CUSTOMERConnectionString"]);
    conTel.Open();

    if (strTelID != "")
    {
        string strtelcmd = ("SELECT tel_type_id, details_type_id, sort_no from TELEPHONE where tel_id =" + strTelID);
        SqlCommand telcmd = new SqlCommand(strtelcmd, conTel);
        SqlDataReader rdrTel = telcmd.ExecuteReader();
        while (rdrTel.Read())
        {

            sdsClient.UpdateParameters["TelTypeID"].DefaultValue = rdrTel["tel_type_id"].ToString();
            sdsClient.UpdateParameters["DetailsTypeID"].DefaultValue = rdrTel["details_type_id"].ToString();
            sdsClient.UpdateParameters["SortNo"].DefaultValue = rdrTel["sort_no"].ToString();

        }
        rdrTel.Close();

    }


    else   if (strFaxID != "")
    {
        string strfaxcmd = ("SELECT tel_type_id, details_type_id, sort_no from TELEPHONE where tel_id ="+ strFaxID);
        SqlCommand faxcmd = new SqlCommand(strfaxcmd, conTel);
        SqlDataReader rdrfax = faxcmd.ExecuteReader();
        while (rdrfax.Read())
        {
            sdsClient.UpdateParameters["TelTypeID1"].DefaultValue = rdrfax["tel_type_id"].ToString();
            sdsClient.UpdateParameters["DetailsTypeID1"].DefaultValue = rdrfax["details_type_id"].ToString();
            sdsClient.UpdateParameters["SortNo1"].DefaultValue = rdrfax["sort_no"].ToString();
        }

        rdrfax.Close();

    }
    else if (strTelID == "")
    {

        SqlCommand cmdaddTel = new SqlCommand("uspAddClientTel",conTel);
        cmdaddTel.CommandType = CommandType.StoredProcedure;

        string strNewTel = (string)e.NewValues["telephone"]; 


        if (strNewTel.Trim().StartsWith("06") || strNewTel.Trim().StartsWith("07") )

            TelTypeID = "2";
        else
            TelTypeID = "1";


        cmdaddTel.Parameters.Add(new SqlParameter("@ClientID", intClientID));
        cmdaddTel.Parameters.Add(new SqlParameter("@TelNo",strNewTel ));
        cmdaddTel.Parameters.Add(new SqlParameter("@TelTypeID", TelTypeID));
        cmdaddTel.Parameters.Add(new SqlParameter("@DetailsTypeID", 1));
        cmdaddTel.Parameters.Add(new SqlParameter("@SortNo1", 1 ));
        cmdaddTel.Parameters.Add(new SqlParameter("@ResultTelID1", ResultTelID1));

        SqlDataReader rdrAddFax = cmdaddTel.ExecuteReader();

    }

    else if (strFaxID == "")
    {

        SqlCommand cmdaddFax = new SqlCommand("uspAddClientTel", conTel);
        cmdaddFax.CommandType = CommandType.StoredProcedure;

        string strNewFax = (string)e.NewValues["fax"];



        cmdaddFax.Parameters.Add(new SqlParameter("@ClientID", intClientID));
        cmdaddFax.Parameters.Add(new SqlParameter("@TelNo", strNewFax));
        cmdaddFax.Parameters.Add(new SqlParameter("@TelTypeID", 3));
        cmdaddFax.Parameters.Add(new SqlParameter("@DetailsTypeID", 2));
        cmdaddFax.Parameters.Add(new SqlParameter("@SortNo1", 1));
        cmdaddFax.Parameters.Add(new SqlParameter("@ResultTelID1", ResultTelID1));

        SqlDataReader rdrAddFax = cmdaddFax.ExecuteReader();
    }


    conTel.Close();


}

and the sps in the updatecommand of formview.

  • 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-27T04:54:13+00:00Added an answer on May 27, 2026 at 4:54 am

    hi all i worked it out at the end. thought it might help beginner like me

      public void functUAD(int intClientID, string TelType, int TelID, string OldTelNumber, string NewTelNumber)
        {
            int ResultTelID = 0 ;
            int TelTypeID ;
            int Result= 0 ;
    
    
            SqlConnection conTel = new SqlConnection();
            conTel.ConnectionString = Convert.ToString(ConfigurationManager.ConnectionStrings["CUSTOMERConnectionString"]);
            conTel.Open();
    
            if (TelType.ToLower() == "fax")
    
                TelTypeID = 3;
    
            else if (NewTelNumber.Trim().StartsWith("06") || NewTelNumber.Trim().StartsWith("07"))
    
                TelTypeID = 2;
            else
                TelTypeID = 1;
    
    
    
           if (OldTelNumber != "" && NewTelNumber != "" )    //update old number with new number
            {
    
    
                SqlCommand cmdUpdateTel = new SqlCommand("uspUpdateClientTel", conTel);
                cmdUpdateTel.CommandType = CommandType.StoredProcedure;
    
                SqlCommand cmdSortNo = new SqlCommand("SELECT sort_no FROM TELEPHONE WHERE tel_id= " + TelID, conTel);
                string SortNo = (string)cmdSortNo.ExecuteScalar();
    
    
                cmdUpdateTel.Parameters.Add(new SqlParameter("@TelID", TelID));
                cmdUpdateTel.Parameters.Add(new SqlParameter("@TelNo", NewTelNumber));
                cmdUpdateTel.Parameters.Add(new SqlParameter("@TelTypeID", TelTypeID));
                cmdUpdateTel.Parameters.Add(new SqlParameter("@DetailsTypeID", 1));
                cmdUpdateTel.Parameters.Add(new SqlParameter("@SortNo", SortNo));
                cmdUpdateTel.Parameters.Add(new SqlParameter("@ResultTelID", ResultTelID));
    
                cmdUpdateTel.ExecuteNonQuery();
    
            }
    
            if (OldTelNumber == "" && NewTelNumber != "")   // add a newnumber
            {
    
                int SortNo = 0 ;
                SqlCommand cmdaddTel = new SqlCommand("uspAddClientTel", conTel);
                cmdaddTel.CommandType = CommandType.StoredProcedure;
    
    
                if (TelTypeID == 1)
                    SortNo = 1;
                else
                {
                    SqlCommand cmdSortNo = new SqlCommand("SELECT MAX(sort_no) from TELEPHONE where tel_id =" + TelID, conTel);
                    int MaxSort = (int)cmdSortNo.ExecuteScalar();
                    SortNo += MaxSort;
                }
                cmdaddTel.Parameters.Add(new SqlParameter("@ClientID", intClientID));
                cmdaddTel.Parameters.Add(new SqlParameter("@TelNo", NewTelNumber));
                cmdaddTel.Parameters.Add(new SqlParameter("@TelTypeID", TelTypeID));
                cmdaddTel.Parameters.Add(new SqlParameter("@DetailsTypeID", 1));
                cmdaddTel.Parameters.Add(new SqlParameter("@SortNo", SortNo ));
                cmdaddTel.Parameters.Add(new SqlParameter("@ResultTelID", ResultTelID));
    
                cmdaddTel.ExecuteNonQuery();
    
            }
    
            if (OldTelNumber != "" && NewTelNumber == "") // delete the old number
            {
    
                SqlCommand cmdDelete = new SqlCommand("RemoveClientTel", conTel);
                cmdDelete.Parameters.Add(new SqlParameter("@TelID",TelID));
                cmdDelete.Parameters.Add(new SqlParameter("@Result", Result));
                cmdDelete.ExecuteNonQuery();
            }
    }
    

    and then you can call the function with appropriate parameters! bye!

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

Sidebar

Related Questions

I have this scenario: I have a mysql database, with a table that contain
I have this scenario: One client sends a message into a msmq queue instance
I have this scenario. I have 10 checkboxes that need to be generated(this list
I have this scenario i have a staging table that contains all the record
In my app, I have this scenario where I need to post an object
I have a scenario like this: I need to pass @id to the stored
I have this scenario: One custom class (Customer) with some properties, like this: public
I have this scenario... 1.- I'm providing a Dynamic Table for wich users can
I have this scenario. I need to show 3 list boxes on a ASP.NET
So...I have this scenario where I have a Foreach loop that loops through 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.