1
我已經具有複選框模板字段一個gridview,我使用C#代碼和基本上,當用戶檢查所有的Checkboxs在數據網格視圖我要添加這些值轉換成數據類型爲Bit的SQL數據庫。 這是我的代碼到目前爲止;從複選框模板字段插入值到SQL數據庫字段類型位
protected void SaveRegisterButton_Click(object sender, EventArgs e)
{
SqlConnection connection;
SqlCommand command;
int numRowsAdded;
int id;
Boolean AttendanceChecked;
foreach (GridViewRow row in GridView2.Rows)
{
if (((CheckBox)row.FindControl("AttendanceCheckBox")).Checked)
{
try
{
// Connecting to the database using the connection string in the web.config file
connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["RegisterConnectionString"].ConnectionString);
// Create an INSERT Sql statement
// To prevent an Sql injection attack, we add parameters with names starting with an @ symbol
command = new SqlCommand("INSERT INTO Attendance(Present, StudentID, LessonID) VALUES(@AttendanceChecked, @StudentID, @LessonID)",
// Replace the parameters with the actual values read from the form
//command.Parameters.AddWithValue("AttendanceChecked", AttendanceCheckBox);
如何將複選框控件的值傳遞到數據類型爲Bit的sql數據庫字段?任何幫助表示感謝,提前致謝!
對不起,我的意思是,當複選框被選中我想保存1中的數據類型字段位,而當它未被選中我想在數據類型字段保存位0。謝謝你的幫助! – user715115 2011-04-21 12:41:41