sqlhelper是一個完全開源的原始碼元件,使用sqlhelper可以方便操作sqlserver、oracle、access等資料庫。文法簡單,提高效能。
SqlHelper 的兩種寫法:
SqlHelper make in Visual studio 2010.support sqlserver,access,oracle databases.
多語句或事務方式:
using (SqlConnection conn = SqlServerHelper.GetConnection())
{
conn.Open();
SqlServerHelper.ExecuteNonQuery(conn,CommandType.Text,"insert into [students] values(@student_name,@class)",
SqlServerHelper.CreateInputParameter("@student_name", SqlDbType.NVarChar, 100, txt_student_name_sqlserver.Text),
SqlServerHelper.CreateInputParameter("@class", SqlDbType.NVarChar, 100, txt_class_sqlserver.Text)
);
g1.DataSource = SqlServerHelper.ReadTable(conn, CommandType.Text, "select * from [students]", null);
g1.DataBind();
}
簡單方式:
SqlServerHelper.ExecuteNonQuery(CommandType.Text,"insert into [students] values(@student_name,@class)",
SqlServerHelper.CreateInputParameter("@student_name", SqlDbType.NVarChar, 100, txt_student_name_sqlserver.Text),
SqlServerHelper.CreateInputParameter("@class", SqlDbType.NVarChar, 100, txt_class_sqlserver.Text)
);