本人通过存储过程从数据库中读取数据到DataReader中(SqlCommand comm=new SqlCommand(StoredProcedureName,Connection); SqlDataReader myReader = comm.ExecuteReader(); 存储过程中的语句: select 字段 from 数据表),现在想将myReader中的多行数据通过button_Click 事件逐条输出到textbox中,如何实现?
解决方案 »
- 将数据库里的备注格式数据按一定范围换算.
- 本地测试没有问题,在客户电脑上出了 See the end of this message for details on invoking
- VS2005(VC++)如何可以调用C#的WCF Service?
- 读,写EXCEL数据的问题
- 方法“XXX”内的代码由设计器生成,不应手动修改?
- 向varlj提问:ie中的F3,F4功能键问题?
- 散分了+呵呵+新年快乐
- winform如何取得treeview所有checkbox被选种的节点,急,在线等
- 两个类的关联为什么一个是用id关联另一个不用id关联的
- winform中 DataGridView如何绑定子对象?
- 关于dataGrid的一些问题
- 命令行程序
{
//write data to textbox
}
{
//write data to textbox
}
else
{
yourReader.Close();
}
textbox.text = myReader["field"].ToString();
}
textbox.text = myReader["field"].ToString();
}========= nod
{
if(Reader.Read())
textBox.Text = Reader["xxx"].ToString();
else
{
MessageBox.Show("已是最后一条数据了。")
Reader.Close();
}
}
if(Reader.Read())
{
a += Reader["xxx"].ToString();
}
textBox.Text = a;
Response.write("<script>alert('数据显示完毕!')</script>")
private void btnDaoru_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection(××.Connection);
SqlCommand comm=new SqlCommand("StoredProcedureName",conn);
comm.CommandType=CommandType.StoredProcedure;
//定义输入参数
SqlParameter parinput1=addFeisi.Parameters.Add("@Date",SqlDbType.SmallDateTime);parinput1.Direction=ParameterDirection.Input;
//给输入参数赋值
parinput1.Value = dtpDate.Value.Date.ToString();
try
{
conn.Open();
SqlDataReader myReader = comm.ExecuteReader();//执行语句
while(myReader.Read())
{
tbJihao.Text = myReader[0].ToString();
tbFeisiliang.Text = myReader[1].ToString(); myReader.Close();
} conn.Close();
} catch(System.Exception en)
{
Console.WriteLine(en.ToString());
conn.Close();
}
}
一定要的话可以把datareader声明成成员变量。
再用顶楼的代码。
SqlDataReader dr;
while(dr.Read())
{
textbox1.text+=dr["字段名"].ToString();
}
这样就可以了
textbox1.text=ds.table[0].row[i]["字段"]
i可以做个静态或者viewstate都行