1

我收到以下错误:

输入字符串的格式不正确

任何人都可以帮助我吗?这是我的输入参数和方法:

public void insertSQL(Dictionary<string,object> objects, string dbConnectionString)
{
    openConnection(dbConnectionString);

    SQLiteCommand command = new SQLiteCommand(sqliteCon);
    command.CommandText = "INSERT INTO AppUser VALUES(@name, @surname)", objects, "Data Source=sample.s3db"
    command.CommandType = CommandType.Text;

    foreach (var param in objects)
    {
        command.Parameters.Add(new SQLiteParameter(param.Key,SqlDbType.NVarChar){ Value =  (String)param.Value} );
        Console.WriteLine(command.Parameters.Count);
    }
    command.ExecuteNonQuery();     
    closeConnection();
}
4

2 回答 2

2

您必须说明您正在为哪些列提供值(其他列将获得其默认值)类似于:

INSERT INTO AppUser (name,surname) VALUES(@name, @surname) ...
于 2012-09-08T22:22:13.227 回答
0

查询中的参数名称应等于您为其赋值的参数:

using (SQLiteConnection connection = new SQLiteConnection(connectionString))
using (SQLiteCommand command = new SQLiteCommand(connection))
{
    command.CommandText = "...";

    command.Parameters.Add("@name", SqlDbType.NVarChar).Value = name;
    command.Parameters.Add("@surname", SqlDbType.NVarChar).Value = value;

    connection.Open();
    command.ExecuteNonQuery();
}
于 2012-09-06T07:51:14.810 回答