2013-05-25 53 views
-2

我有表中的数字。例如0050.在数据库中完全是0050,因为我设置了ZEROFILL。 但现在当我想在C#中选择这个数字时,它只显示50个没有2个空值。C#MySQL SELECT null

我的代码:

private void button4_Click(object sender, EventArgs e) 
    { 
     string input = label1.Text.Trim(); 
     string conn = "server=46.28.110.147;user=asqasdqdq;password=qdqdqd;database=qdqdqwdqd;"; 
     MySqlConnection myconn = new MySqlConnection(conn); 
     string sql = "SELECT numbers FROM vfr WHERE used=0 ORDER BY numbers LIMIT 1"; 
     MySqlDataAdapter da = new MySqlDataAdapter(sql, myconn); 
     DataTable dt = new DataTable(); 
     da.Fill(dt); 

     label1.Text = dt.Rows[0][0] + ""; 


    } 

谢谢

+0

你似乎混淆:字符串“0050”是不一样的50 –

+1

是一个数字,(其中的方式是很糟糕的名字对于包含一个数字的列)是一个int类型。 ZeroFill是无用的,除非它是一个字符串类型,任何前导零将被丢弃,因为ints没有他们0050 = 50. –

+0

但我只有SELECT的问题。所以我编辑了第一篇文章。谢谢 –

回答

1

因为不管什么ZEROFILL指一个数字,存储为一个数不包含任何格式的信息。如果你将这个数字存储为一个字符串,那么也许吧,但是如果你把它转换成一个数字,那么你把它带入C#时,你仍然会遇到同样的问题。数字在C#中也不包含格式信息。控制格式是一个独立的过程。退房.NetFormatStrings

var x = 0050; 
Console.Write(x); 
Console.Write(x.ToString("0000")); 
+0

谢谢,但我不能使用它,因为在数据库中有更多的数字。 –

+0

顺便说一下,问题只在于SELECT,UPDATE是针对另一个操作。 :) 我编辑的第一篇文章 –

0
select * from table where numbers is null 

select * from table where numbers is not null 

update table set numbers =1 where numbers is null 

update table set numbers =1 where numbers is not null 
+0

谢谢,但我不能使用它,因为我有另一个SELECT命令: 选择数字从vfr在哪里使用= 0 ORDER BY数字LIMIT 1 –

+1

该OP似乎是使用“null”意思是“零“,而不是SQL”null“。如果*关于'null'的问题*,我会建议更多关于'null'和'not null'测试的解释。 – kdgregory

+0

select isnull(numbers,0),isnull(null,123) – Virus