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.

Recommended Answers

All 9 Replies

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

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.......

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

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

Hello I tried your method and it was unsuccessful please see attached error message.

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.