Skip to content

Converting grid values to lower case for update

always gull

Asked Feb 25, 2009, 9:03 AM EST3 answers
Share
LinkedInX
Hi I have a problem i hgaave a table in data grid view and i am updating data from data using a button. what i need to do is once the user update the data and click on update button i want to convert all string values to lower case. i am not using data table to populate my grid, is their any way that i can do that  here is my code i am using to upgrade my grid

private void cmd_update_record_Click(object sender, EventArgs e)
        {



            if (dgRepair.RowCount == 0)
            {

                MessageBox.Show("No data available for update");
            }


            else
            {
              
                DataSet ChangedRepDataSet = new DataSet();
                ChangedRepDataSet = ds_rep.GetChanges();
               
               
                if (ChangedRepDataSet != null)
                {
                   
                   
                    // Intializing object of Connectionclass to open connection
                    conn_obj = new ConnectionClass();
                    store_connection = conn_obj.connect();
                    // Sqlcommand object
                    SqlCommand cmdupdate;
                    cmdupdate = new SqlCommand();
                    cmdupdate.CommandType = CommandType.StoredProcedure;
                    cmdupdate.CommandText = "Update_Status_Grid";

                    //opening connection
                    cmdupdate.Connection = store_connection;
                    store_connection.Open();

                    //Adding Parameters  for Repair table

                    cmdupdate.Parameters.Add("@OrgDescription", SqlDbType.VarChar, 100, "Description");
                    cmdupdate.Parameters["@OrgDescription"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@Description", SqlDbType.VarChar, 100, "Description");
                    cmdupdate.Parameters.Add("@OrgStatus", SqlDbType.VarChar, 15, "Status");
                    cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@Status", SqlDbType.VarChar, 15, "Status");
                    cmdupdate.Parameters.Add("@OrgPartDes", SqlDbType.VarChar, 50, "PartDes");
                    cmdupdate.Parameters["@OrgPartDes"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@PartDes", SqlDbType.VarChar, 50, "PartDes");
                    cmdupdate.Parameters.Add("@OrgRepAction", SqlDbType.VarChar, 50, "RepAction");
                    cmdupdate.Parameters["@OrgRepAction"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@RepAction", SqlDbType.VarChar, 50, "RepAction");
                    cmdupdate.Parameters.Add("@OrgId", SqlDbType.BigInt ,1000, "Id");
                    cmdupdate.Parameters["@OrgId"].SourceVersion = DataRowVersion.Original;

                   //Adding the Parameters for invoice table
                    cmdupdate.Parameters.Add("@OrgRepCost", SqlDbType.Money, 1000, "RepCost");
                    cmdupdate.Parameters["@OrgRepCost"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@RepCost", SqlDbType.Money, 1000, "RepCost");
                    cmdupdate.Parameters.Add("@OrgPaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
                    cmdupdate.Parameters["@OrgPaymentPaid"].SourceVersion = DataRowVersion.Original;
                    cmdupdate.Parameters.Add("@PaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
                   
                    da_rep.UpdateCommand = cmdupdate;
                 





                    if (check == true)
                    {

                        try
                        {
                            da_rep.Update(ds_rep, "Repair");
                            ds_rep.AcceptChanges();
                        }


                        catch (Exception ex)
                        {
                            MessageBox.Show("Their is some problem in updating make sure you are entering right values                " +
                            ex);
                        }
                    }
                   
                       //}
                               
                //}
                }
           else
                {
                    MessageBox.Show("no changes made");
                }

                //int modifiedRows = da_cus.Update(myChangedDataset);
                //MessageBox.Show("Database has been updated successfully:" + no_of_rows_chang + "  rows has been changed");

        }

can any one help me

Thanks

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    I give you a small exmaple of how to reduce a sting to lower case

    string myContent = "sDsdsU";
     myContent.ToLower(new System.Globalization.CultureInfo("en-US"));

    The result will be

    sdsdsu
    0
  • 0
    thanks for the reply i show what i was trying

    cmdupdate.Parameters.Add("@Description".ToLower(new System.Globalization.CultureInfo("en-US")),SqlDbType.VarChar,25,"Description".ToLower(new System.Globalization.CultureInfo("en-US"))).ToString().ToLower(new System.Globalization.CultureInfo("en-Us"));

    so i am trying Lower case with parameters with the column but seems to be not working for me.
    is their any other way i can do it, or is their any way that i can convert stored procedure parameter value to lower case when i am using column name as source for the value.
    0
  • Bechir Bejaoui
    0
    Well I have a good idea for your case,
    You don't try to transform your data to  lower case from the sql paramters so keep them normal, in the other hand you create a Trigger on the update action at the data base  level

    I give you an example of trigger
    SQL
    USE yourDataBase;
    GO
    IF OBJECT_ID ('yourtable.
    converter', 'TR') IS NOT NULL
       DROP TRIGGER yourtable.converter;
    
    GO
    CREATE TRIGGER converter
    ON yourTable.yourfield
    AFTER INSERT, UPDATE 
    AS 
    UPDATE yourTable SET yourFiled = LOWER(YourFiledParameter);
    GO
    
    of corse you can embed this trigger within yourstored procedure
    To create a trigger within Visual Studio take a look on this article

    http://www.c-sharpcorner.com/UploadFile/pk_khuman/ManagedTrigersUsingCSharp02202007230729PM/ManagedTrigersUsingCSharp.aspx?ArticleID=fec8a799-1b2a-4429-9b4f-406ca3f0c019
    0