Evening,

I have built a program with full SQL functionality (from pulling to adding etc).

I am using stored proceedures for the SQL queries.

I seem to have a problem when adding / updating a SQL VARCHAR column when the item being added / updated has a space (ie 'Add This').

So my question is, what extra functionality do i need to add to allow a string to be added that has more than one word into a single column?

Or do i have to do something like replace the space with an underscore when adding then change it when showing it to the user?

Thanks for your time.

Hello,

Actually you're facing a very common problem in SQL.........My opinion to you is that you should replace the spaces by "CamelCasing" or just by "Underscores"......If you're using a datagrid or gridview etc. to display those items,just go to their properties and write in the "AlternateDataString" column or something likewise........
Hope this helps ya.......

Edited 6 Years Ago by KM499: n/a

If this is in the SQL query try using [] around the column name.

I will try this when i get home and post the results

Hello,

Actually you're facing a very common problem in SQL.........My opinion to you is that you should replace the spaces by "CamelCasing" or just by "Underscores"......If you're using a datagrid or gridview etc. to display those items,just go to their properties and write in the "AlternateDataString" column or something likewise........
Hope this helps ya.......

I thought it would be a common problem, just a query on the camel casing, when it comes to adding it to the db thats simple but when it comes to pulling it from the db how do i go about splitting it by the 2nd capital letter as this could be 1 of 26 capitals (for example, input "Add This" into db by using C# to remove the space so it becomes AddThis, but when pulling it how do i seperate it back to "Add This" instead of "AddThis").

Also doing it with camel casing would be to rely on the user putting a capital letter with every new word (unlikley), so how would i code C# to check for the available whitespace, then convert the letter next to it to UpperCase?

Thanks for your time

Please post some code so we can see what you are doing.

I'm done for the night now so maybe someone else can help you.

Edited 6 Years Ago by nick.crane: n/a

Please post some code so we can see what you are doing.

I'm done for the night now so maybe someone else can help you.

Hello,

As Requested

private void sqlNewRowForCategories()
        {
            try
            {
                oSQLConn.mySQLConn.Open();
                oSQLConn.mySqlCmd = new SqlCommand("EXEC addNewCategory " + txtName.Text, oSQLConn.mySQLConn);
                oSQLConn.mySqlCmd.ExecuteNonQuery();
                oSQLConn.mySQLConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.ToString());
            }
            finally
            {

            }
        }

Obviously this only partial code, txtName.Text is where the user enters the new name to be added,

SQL Stored Procedure is

ALTER PROCEDURE dbo.addNewCategory

	@CatDesc varchar (25)
	
AS
	INSERT INTO	tblCategory(CategoryDescription)
	VALUES		(@CatDesc)
RETURN

Hi,

try this

oSQLConn.mySqlCmd = new SqlCommand("EXEC addNewCategory " + "'" + txtName.Text + "'", oSQLConn.mySQLConn);

Ionut

Edited 6 Years Ago by Ionelul: n/a

Hi,

try this

oSQLConn.mySqlCmd = new SqlCommand("EXEC addNewCategory " + "'" + txtName.Text + "'", oSQLConn.mySQLConn);

Ionut

Well well well, that worked, why is it always the simplest things that make it so difficult ;).

Thank you Ionelul, and everybody else who helped.

This question has already been answered. Start a new discussion instead.