62,266
社区成员
发帖
与我相关
我的任务
分享
using (var dlg = new OpenFileDialog())
{
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName = dlg.FileName;
};
};
byte[] buffer=(byte)(reader["Content"]);//读取数据库中的文件内容
FileStream stream=File.Create(path);//path是文件路径
stream.Write(buffer,0,buffer.Length);//写入文件
stream.Close();//关闭文件流byte[] buffer=(byte)(reader["Content"]);
public void ShowData()
{
//实例化Connection对象
SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa");
//实例化Command对象
SqlCommand command = new SqlCommand("select * from UserInfo where sex=1", connection);
//打开Connection对象
connection.Open();
//得到DataReader的实例,注意使用了CommandBehavior这个参数,以便同时关闭Connection
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
//如果当前记录还有下一条记录,则循环不会终止
while (reader.Read())
{
Response.Write("<tr><td>" + reader.GetInt32(0) + "</td>");//按照列顺序和对应类型直接读取值
Response.Write("<td>" + reader.GetString(1) + "</td>");//按照列顺序和对应类型直接读取值
Response.Write("<td>" + reader.GetString(2) + "</td>");//按照列顺序和对应类型直接读取值
Response.Write("<td>" + reader.GetByte(3) + "</td>");//按照列顺序和对应类型直接读取值
//下面是按照列顺序直接读取值,并且根据值来判断最终显示结果
Response.Write("<td>" + (reader.GetBoolean(4)==true?"男":"女") + "</td>");
//根据列顺序读,列的值需要做相应转换
Response.Write("<td>" + reader[5].ToString() + "</td>");
//根据列名来读取,列的值需要做相应转换
Response.Write("<td>" + reader["Phone"] + "</td>");
Response.Write("<td>" + reader["Email"].ToString() + "</td></tr>\n");
}
reader.Close();
}