如何在msaccess数据库中保存复选框值 [英] how to save checkbox value in the msaccess database

查看:67
本文介绍了如何在msaccess数据库中保存复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Datagridview中进行如下设计;



天会议1会话2



1复选框检查包装盒

2复选框复选框



i想在数据库中保存以上记录。



我怎么能用csharp?



将上面的复选框值插入msaccess数据库。



请帮帮我。



问候,

Narasiman P.

解决方案

将值保存在数据库中,就像这样查询

 SQL =  插入table1(checkboxcolumn1,checkboxcolumn2)值( +(转换 .ToString(dgv [ column ,row])==   True ?-1:0)+   +(转换 .ToString(dgv [ column ,row] )==   True? -1:0)+   


  string  connStr =    Provider = Microsoft.ACE.OLEDB.12.0; Data Source = application.accdb; Persist Security Info = True; 
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = connStr;

OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.InsertCommand = new OleDbCommand();
foreach (DataGridViewRow dgvr in datagrid1.Rows)
{
// 获取基础数据行
DataRow dr =((DataRowView)dgvr.DataBoundItem)。行;

// 我假设你的tabel包含三列Id int,Session1 boolean,Session2 boolean

adapter.InsertCommand.CommandText = INSERT INTO表(Id,Session1) ,Session2) + VALUES( + dr [ ] + +(dr [ session 1])? 1 0 + ',' +(dr [ session 2]) ? 1 0 + ');;
conn.Open();
adapter.InsertCommand.Connection = conn;
adapter.InsertCommand.ExecuteNonQuery();
}


试试这个



 SQL =  插入table1(checkboxcolumn1,checkboxcolumn2)值(' + checkBox1.IsChecked.ToString() +  ',' + checkBox2.IsChecked.ToString()+  '); 


Design as follows in Datagridview ;

Days session 1 session 2

1 check box check box
2 check box check box

i want to save the above record in the database .

for that how can i do using csharp?

to insert the above checkbox values into the msaccess database.

Please help me.

Regards,
Narasiman P.

解决方案

to save the value in database like query like this

SQL="insert into table1(checkboxcolumn1,checkboxcolumn2)values(" + (Convert.ToString(dgv[column,row])=="True" ? -1:0) + "," + (Convert.ToString(dgv[column,row])=="True" ? -1:0) + ")"


Try this

string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=application.accdb;Persist Security Info=True";
       OleDbConnection conn = new OleDbConnection();
       conn.ConnectionString = connStr;

       OleDbDataAdapter adapter = new OleDbDataAdapter();
       adapter.InsertCommand = new OleDbCommand();
       foreach (DataGridViewRow dgvr in datagrid1.Rows)
       {
           // Get the underlying datarow
           DataRow dr = ((DataRowView)dgvr.DataBoundItem).Row;

           // I am assuming your tabel contains three column Id int, Session1 boolean,  Session2 boolean          

           adapter.InsertCommand.CommandText = "INSERT INTO table (Id, Session1, Session2)" + " VALUES(" + dr["Days"] + ", " + (dr["session 1"])?1:0 + "', '" + (dr["session 2"])?1:0 + "');";
           conn.Open();
           adapter.InsertCommand.Connection = conn;
           adapter.InsertCommand.ExecuteNonQuery();
       }


Try this

SQL="insert into table1(checkboxcolumn1,checkboxcolumn2)values('" +checkBox1.IsChecked.ToString()+"','"+checkBox2.IsChecked.ToString()+"')";


这篇关于如何在msaccess数据库中保存复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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