C#INSERT到数据库 [英] C# INSERT into data base

查看:275
本文介绍了C#INSERT到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

Exception thrown: 'System.InvalidOperationException' in System.Data.SQLite.dll



int s = 1;




int s = 1;

using (SQLiteConnection conn = new SQLiteConnection("datasource=baza.db"))
                       {
                           using (SQLiteCommand cmd = new SQLiteCommand(conn))
                           {
                               try
                               {

                                   cmd.CommandText = @"INSERT INTO rezultatisolo (uporabnik_id, cas) VALUES (@uporabnik_id, @cas)";
                                   cmd.Connection = conn;
                                   cmd.Parameters.Add(new SQLiteParameter("@uporabnik_id", this.label3.Text));
                                  cmd.Parameters.Add(new SQLiteParameter("@cas", this.s));
                                   cmd.ExecuteNonQuery();

                               }

                               catch
                               {
                                   MessageBox.Show("ERROR");
                               }
                           }
                           conn.Close();
                       }





我尝试过:



将一些数据插入数据库



What I have tried:

insert some data into data base

推荐答案

再次尝试使用以下catch:

Try again using the following catch:
catch (Exception ex)
{
   MessageBox.Show(ex.Message);
}



然后至少你会得到更多关于错误的信息。



如果 uporabnik_id 是自动增量的,您不应该在INSERT语句中包含它。


Then at least you will get some more information about the error.

If uporabnik_id is autoincremented, you should not include it in your INSERT statement.


这篇关于C#INSERT到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆