2016-06-16 14 views
-1

이제이 문제를 해결하려고합니다. 하지만 왜 작동하지 않았는지 모르겠습니다.C에서 sqlite db 파일을 업데이트하려고합니다. #

datagridview 양식의 데이터 변경이 끝났지 만 데스크톱의 sqlite 파일은 변경되지 않았습니다. 저를 가르 칠 수있는 사람은

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); 


    } 

} 

}

있습니까?

+0

'adapter.UpdateCommand'에 sql 텍스트를 지정해야합니다. 이제'SelectCommand' 텍스트 만 있습니다. –

+0

업데이트 명령에 데이터 수정을위한 지침이 필요하다는 의미입니까? –

+0

예, UPDATE Skill ...이됩니다. –

답변

0

나는이 방법을 사용합니다 그들은 특정 폴더에서 액세스 할 때 내가 sqlite가 문제를 보았다, 당신은 또한 파일 권한을 확인해야

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)); 

} 

을 바탕 화면은 하나였다.

+0

코드를 수정하십시오. 그것도 컴파일되지 않습니다. –

+0

C#은 대소 문자를 구분합니다! –

+0

죄송합니다 Alexander, 저는 이것을 휴대폰에서 썼습니다. – Dwight