本文介绍了数据不是来自数据库的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从数据库中获取数据.
我将用于从表中选择值的存储过程编写为
Hi,
I''m Trying to get data from a Database.
I wrote the stored Procedure for Selecting the values from the table as
ALTER Procedure [dbo].[Select_Students](@Sno int)
As
Begin
If @Sno Is Null
Select Sno,Sname,Class,Fees From Stu
Else
Select Sname,Class,Fees From Stu Where Sno=@Sno
End
并将获取"按钮的代码编码为
and code for the Get button as
private void button1_Click(object sender, EventArgs e)
{
cmd.Parameters.Clear();
ds = new DataSet();
da = new SqlDataAdapter();
cmd.CommandText = "Select_Students";
da.Fill(ds, "Stu");
if (ds.Tables[0].Rows.Count > 0)
{
textBox2.Text = ds.Tables[0].Rows[0][1].ToString();
textBox3.Text = ds.Tables[0].Rows[0][2].ToString();
textBox4.Text = ds.Tables[0].Rows[0][3].ToString();
}
else
MessageBox.Show("Record Not Existed");
}
但是数据不是来自数据库.
谁能告诉我这段代码中的问题.
非常感谢
But the data is not coming from the database.
Can any one tell me the problem in this code.
Thank you so much
推荐答案
ds = new DataSet();
da = new DataAdapter(cmd);
da.Fill(ds, "Stu");
然后我在数据库中执行了存储过程,因此执行得很好.
添加代码后,它将显示所有记录的最高记录值.
and I executed my stored procedure in database there it get executed nicely.
after adding your code it displays the top record values for all.
da = new SqlDataAdapter(cmd);
希望这会有所帮助!
Hope this helps!
这篇关于数据不是来自数据库的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!