C# I';我正在尝试用c更新sqlite数据库文件#
现在我正试图解决这个问题。但我不知道为什么它不起作用 我已经完成更改datagridview表单中的数据,但桌面中的sqlite文件没有更改C# I';我正在尝试用c更新sqlite数据库文件#,c#,sqlite,datagridview,C#,Sqlite,Datagridview,现在我正试图解决这个问题。但我不知道为什么它不起作用 我已经完成更改datagridview表单中的数据,但桌面中的sqlite文件没有更改 namespace Ex1 { public partial class Form1 : Form { int initValue = 0; String chkString; SQLiteConnection conn = new SQLiteConnection("Data Source=I:\\Coding\\VS\\Stud
namespace Ex1
{
public partial class Form1 : Form
{
int initValue = 0;
String chkString;
SQLiteConnection conn = new SQLiteConnection("Data Source=I:\\Coding\\VS\\Study1\\Ex1\\Ex1\\Test.db;Version=3;");
SQLiteDataAdapter adapter = null;
BindingSource bsOrigin = null;
DataSet ds = null;
Random rand = new Random();
KnownColor[] Colors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
KnownColor randColor;
public Form1()
{
InitializeComponent();
textBox1.Text = initValue.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
bsOrigin = new BindingSource();
ds = GetData();
bsOrigin.DataSource = ds.Tables[0];
dataGridView1.DataSource = bsOrigin;
}
private DataSet GetData()
{
adapter = new SQLiteDataAdapter("SELECT * from Skill", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
adapter = new SQLiteDataAdapter("SELECT * from Skill", conn);
BindingSource bs = (BindingSource)dataGridView1.DataSource;
DataTable dt = bs.DataSource as DataTable;
adapter.Update(dt);
}
}
}
有人可以教我吗?我使用这种方法:
public void saveData ()
{
SQLiteDataConnection con = new SQLiteDataConnection("yourconnectionstring");
SQLiteDataAdapter da= new SQLiteDataAdapter("Select statement", con);
SQLiteCommandBuiler com=new SQLiteCommandBuiler(da);
DataSet ds= new DataSet ();
DataTable dt = new DataTable ():
DataRow dr;
con.Open();
da.fill(ds, "tablename");
cn.Close();
dt=ds.Tables["tablename"];
dr=dt.NewRow();
dr["rowname"]=value;
//"same for the other rows"
dr.Rows.Add(dr);
da.Update(dt.Select(null, null, DataViewRowState.Added));
}
您还应该检查文件权限,当从某些文件夹访问sqlite时,我发现它们有问题,桌面就是其中之一。您应该为
适配器.UpdateCommand
指定sql文本。现在您只有SelectCommand
文本。这是否意味着更新命令需要一些修改数据的说明?是的,它将是Update Skill…
。C区分大小写!抱歉Alexander,这是我用手机写的。