473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
8 3240
r035198x
13,262 8TB
MySQL does not have a System.object type.
What makes you think that it's stored as System.object?
Jun 5 '09 #2
SLauren
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
5,058 Expert 4TB
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
SLauren
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
5,058 Expert 4TB
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
r035198x
13,262 8TB
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
SLauren
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, 339 views)
File Type: jpg testdb.jpg (2.9 KB, 134 views)
Jun 5 '09 #8
Atli
5,058 Expert 4TB
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

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
1
by: Scott M. Lyon | last post by:
I've got a stored procedure that takes a few parameters as input parameters, and one output parameter (a uniqueidentifier). After the stored procedure call, I need to return that output parameter...
1
by: Scott M. Lyon | last post by:
I've got a stored procedure that takes a few parameters as input parameters, and one output parameter (a uniqueidentifier). After the stored procedure call, I need to return that output parameter...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
6
by: joerg | last post by:
Hello world, my program connects to a db2 database and needs to find out the column names and data types for a specific table. The code works fine with mysql and derby, but returns an empty...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.