datagirdview和listview,删改查sqlserver数据库的小结
//创建DBhelper数据库链接文件
private static string sqlcon = "server=.;database=myschool;uid=sa;pwd=sa";
public static SqlConnection connection = new SqlConnection(sqlcon);
============================================================
//首先是lv控件的列表显示 ,(listview)
// 清空当前lv表中内容
listview.Items.Clear();
string sql = "select * from question";
//引用DBhelper中的数据库链接
SqlCommand command = new SqlCommand(sql,DBhelper.connection);
//打开数据库,并用dr读取记录
DBhelper.connection.Open();
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
ListViewItem lvi = new ListViewItem(dr["Question"].ToString());
lvi.SubItems.AddRange(new string[] { dr["Answer"].ToString(), dr["Difficulty"].ToString(), dr["SubjectId"].ToString(), dr["OptionA"].ToString(), dr["OptionB"].ToString(), dr["OptionC"].ToString(), dr["OptionD"].ToString() });
相关文档:
SQL-Structured Query Language
--(开启SQL服务:net start mssqlserver)
--(在命令行中输入'sqlwb'命令可打开SQL管理器 )
--(如果 ......
现在一般常用的有以下2种方法:
1. select top @pagesize * from table1 where id not in (select top @pagesize*(@page-1) id from table1 order by id) order by id
2. select * from (select top @pagesize * from (select top @pagesize*@page * from table1 order by id) a order by id desc) b or ......
sqlserver中:
1 /*
2 1 * Description:对数据表进行行列转换
3 2 * Author:llf
4 3 * 调用说明:exec SP_RowChangeCol '学生成绩表','姓名','课程','分数','desc',0,0,'where 年级=''一年级'''
& ......