[英]SQLite return wrong string value C#
I have local sqlite db with some values.我有一些值的本地sqlite db。 And i have "name" and "descritption" columns with "string" type.我有“字符串”类型的“名称”和“描述”列。 In this cell of columns can be values like "32145152174524132151421".在此列单元格中可以是“32145152174524132151421”之类的值。 When i tries to get values using System.Data.SQLite library, in any cases using reader.GetValue().toString() or reader.GetString(), i got values like "32321541e+35" or InvalidCast exception, but DB stores normal values.当我尝试使用 System.Data.SQLite 库获取值时,在任何情况下使用 reader.GetValue().toString() 或 reader.GetString() 时,我都会得到类似“32321541e+35”或 InvalidCast 异常的值,但 DB 存储正常值。
SQLite and his problems with CastValues just killing me. SQLite 和他在 CastValues 方面的问题简直要了我的命。 Can someone help me?有人能帮我吗?
"Zakupki_name" and "Zakupki_description" have "string" data type. “Zakupki_name”和“Zakupki_description”具有“字符串”数据类型。
I wrote it without a dot at the end, but in DB it saves with dot.我写的最后没有点,但在 DB 中它用点保存。
"Zakupki_name" Save in DB - 12323141276876900118036480. Returns by Code - 1.23231412768769e+25 “Zakupki_name”保存在数据库中 - 12323141276876900118036480。按代码返回 - 1.23231412768769e+25
"Zakupki_description" Save in DB - 123444441521613002768384. Returns by Code - 1.23444441521613e+23 “Zakupki_description”保存在数据库中 - 123444441521613002768384。按代码返回 - 1.23444441521613e+23
Code for getting data from the database.从数据库中获取数据的代码。
SQLiteCommand command = new SQLiteCommand(@"SELECT Zakupki_id,
Zakupki_name,
Zakupki_description,
Zakupki_update_date,
Zakupki_value_limit
FROM Zakupki;",connection);
SQLiteDataReader reader = command.ExecuteReader();
int rowCount = GetRowCount(Tables.Zakupki);
if (rowCount != 0)
{
zakupkis = new List<Zakupki>();
while (reader.Read())
{
zakupkis.Add(new Zakupki(reader.GetInt32(0), reader.GetValue(1).ToString(), reader.GetValue(2).ToString(), DateTime.Parse(reader.GetString(3)), double.Parse(reader.GetValue(4).ToString())));
}
}
Code for insert values to db.将值插入数据库的代码。
public void InsertZakupku(string name, string description,double value_limit)
{
//Добавить закупку
try
{
createConnection();
SQLiteCommand command = new SQLiteCommand(string.Format(@"INSERT INTO Zakupki (
Zakupki_name,
Zakupki_description,
Zakupki_update_date,
Zakupki_value_limit)
VALUES ('{0}','{1}','{2}','{3}');", name, description, DateTime.Now, value_limit), connection);
command.ExecuteNonQuery();
closeConnection();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
closeConnection();
}
Using method to insert value.使用方法插入值。
sQLiteClient.InsertZakupku(zakupkiName.Text, zakupkiDescription.Text, double.Parse(zakupkiValue.Text));
通过使用varchar(255)
而不是string
或text
解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.