数据库的检索,大家帮忙啊 select txt from table1 where date=getdate() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select text from table where date='2004:4:30' select 文本字段 from 表 where time='2004-4-30' string date=textbox.Text.Trim();//如果输入查询时间SqlConnection conn=new SqlConnection(connt_str);string sql="select txt from table where date='"+date+"'";string text=null;byte[] mybyte=new byte[1024];//设置字符缓冲区try{ conn.Open(); SqlCommand comm=new SqlCommand(sql,conn); SqlDataReader dr=comm.ExecuteReader(); if(dr.Read()){ text=dr["txt"].ToString(); } dr.Close(); conn.Close(); // 完成从数据库读出查询内容到text中; } catch(Exception ee){ MessageBox.Show(ee.Message); } ///////////////////// 以下是把text中的内容读到一个自己建立的txt的文本文件中///当然这个可以自己选择时候要这么做,因为看楼主好象是要这个意思/////////////////////////// 当然以下内容完全可以不要,可以直接把text中的内容显示在richtextbox中,//不过如果要以日志等形式保留的话,以下可以参考下 try{ FileStream fs=new FileStream(filename,FileAccess.Write,FileMode.CreateNew); mybyte=System.Text.Encoding.Ascii.GetByte(text); fs.Read(mybyte); //把缓冲区内容读入文件流 fs.Clsoe(); } catch(Exception ee){ MessageBox.Show(ee.Message); } wish u good luck Greatsft Sqlcommand cmd=New Sqlcommand("select time from table" ,this.con);this.con.open();SqlDataReader reader= reader.ExecuteReader ( );while(reader.Read()){ this.Listbox1.Items.Add(reader.GetDataTime(0));}this.reader.close();this.con.close();private void Listbox1_SelectedIndexChanged(object sender, System.EventArgs e){DataTime time=Convert.ToDataTime(Listbox1.SelectedItem)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^接下来 把time当为参数穿给下一条语句 求只连接一次数据库的方法? C#Socket只能连接一次问题 (急)如果把DataGridView中显示的数据,全部放到DataTable中 分不多,求个怪癖的问题 数据绑定问题 文本框的内容显示为全选中状态????? 我在C#中连接MySql出错!!!! 请教:要实现这样的效果,要应用什么技术??? sql图片存储和读取 是不是vs的bug,为什么我的aspx会出现脚本错误 以后要多多请教这里的前辈们了,先拜拜码头散散分 等!急!
SqlConnection conn=new SqlConnection(connt_str);
string sql="select txt from table where date='"+date+"'";
string text=null;
byte[] mybyte=new byte[1024];//设置字符缓冲区
try{
conn.Open();
SqlCommand comm=new SqlCommand(sql,conn);
SqlDataReader dr=comm.ExecuteReader();
if(dr.Read()){
text=dr["txt"].ToString();
}
dr.Close();
conn.Close(); // 完成从数据库读出查询内容到text中;
}
catch(Exception ee){
MessageBox.Show(ee.Message);
}
/////////////////////
以下是把text中的内容读到一个自己建立的txt的文本文件中
///当然这个可以自己选择时候要这么做,因为看楼主好象是要这个意思/
////////////////////////
// 当然以下内容完全可以不要,可以直接把text中的内容显示在richtextbox中,
//不过如果要以日志等形式保留的话,以下可以参考下
try{
FileStream fs=new FileStream(filename,FileAccess.Write,FileMode.CreateNew);
mybyte=System.Text.Encoding.Ascii.GetByte(text);
fs.Read(mybyte); //把缓冲区内容读入文件流
fs.Clsoe();
}
catch(Exception ee){
MessageBox.Show(ee.Message);
} wish u good luck
Greatsft
this.con.open();
SqlDataReader reader= reader.ExecuteReader ( );while(reader.Read())
{
this.Listbox1.Items.Add(reader.GetDataTime(0));
}
this.reader.close();
this.con.close();private void Listbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataTime time=Convert.ToDataTime(Listbox1.SelectedItem)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^接下来 把time当为参数穿给下一条语句