By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

Empty string is stored as system.object in mysql column!

P: 60
Hi,

I am passing empty string from Business Logic(C#) to Data Access Layer, but it is getting stored as "system.object" in mysql column after executing the insert query. Can anybody suggest what should i do, as i am expecting the empty string to be stored in mysql column as it is??

Thanks In Advance,
Lauren
Jun 5 '09 #1
Share this Question
Share on Google+
8 Replies


10K+
P: 13,264
MySQL does not have a System.object type.
What makes you think that it's stored as System.object?
Jun 5 '09 #2

P: 60
I have declared that column as varchar and the default value is null. But when the value for that column from business logic is coming as (""), then it is stored as "system.object" which is a string. It is not storing as a type.Can you please suggest where am i going wrong??

Thanks,
Lauren
Jun 5 '09 #3

Atli
Expert 5K+
P: 5,058
If it is being stored as "System.Object", I'm guessing C# is not aware that it is supposed to be a string when you insert it.

Perhaps you just need to cast it as a string before you insert it into the query.
Like:
Expand|Select|Wrap|Line Numbers
  1. string emptyString = (String)yourObject;
  2. string sql = String.Format("INSERT INTO whatever VALUES('{0}')", emptyString);
Jun 5 '09 #4

P: 60
Thanks for the quick response.
I am using "DBType.string" for the input parameter to the stored procedure before executing it. Upto this point the string which is coming from the business logic as (""). But after executing the query when i look at the data, it is stored as "system.object".

Thanks,
Lauren
Jun 5 '09 #5

Atli
Expert 5K+
P: 5,058
Could you show us the code you use to create the query? (Or execute the procedure, or whatever is inserting the data.)

Without actually knowing what your code is doing, I can only guess that the problem is what I described in my last post.
Jun 5 '09 #6

10K+
P: 13,264
You are not making much sense. Where are you looking at it and seeing it as System.object? Like I said MySQL does not have that type. It's a .NET type.
Post the .NET code that led you to believe that the value was stored as a System.object type.
Jun 5 '09 #7

P: 60
Expand|Select|Wrap|Line Numbers
  1. public int Create(ref Entity EntityInstance)
  2. {
  3.       QueryObject queryInstance = new QueryObject();
  4.       queryInstance.Query = "Create";
  5.       DbParam dbParamName = new DbParam("strName", DbType.String,  EntityInstance.Name);
  6.      queryInstance.AddInParameter(dbParamName);
  7.      DbConnection dbConnection;
  8.      DbTransaction databaseTransaction;
  9.     Database dbInstance = DBO.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted, out dbConnection, out databaseTransaction);
  10.     // This writes the data into the table using the stored procedure "Create"
  11.     error = DBO.WriteDataItems(ref dbInstance, ref databaseTransaction, ref queryInstance);   
  12.  
  13. }
EntityInstance is filled by the business logic and EntityInstance.Name is coming as an empty string.
After writing the data into the table after executing the query its getting stored as a string "system.object".


// Procedure
DELIMITER $$

DROP PROCEDURE IF EXISTS `DB`.`test` $$
CREATE DEFINER=`root`@`%` PROCEDURE `test`(IN strName varchar(30))
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION set ex = -1;
SET ex := 0;

INSERT INTO Test (Name) VALUES (strName);

END $$

DELIMITER ;

I have attached two snap shot for this issue.

Thanks
Lauren
Attached Images
File Type: jpg test.jpg (16.3 KB, 322 views)
File Type: jpg testdb.jpg (2.9 KB, 109 views)
Jun 5 '09 #8

Atli
Expert 5K+
P: 5,058
Try changing line #5 in that code to:
Expand|Select|Wrap|Line Numbers
  1. DbParam dbParamName = new DbParam("strName", DbType.String,  (EntityInstance.Name as string));
If the EntityInstance.Name is set as an empty Object, rather than a empty string, then this should fix it.

If not, then I would guess the problem is deeper, withing the EntityInstance or DbParam classes.

In any case... somewhere in that code, your suppsoedly emtpy string, EntitiyInstance.Name, is being treated as an Object, which would make it's ToString return "System.Object", which is getting into your database.

Go through your code and make sure this string is being treated as a string everywhere.

Look for any place your string might be stored in a HasTable or such. They store all things as Objects, and need to be told to convert things back into their original type.
Jun 5 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.