如何在文本框或标签C#中显示数据 [英] how to show data in textbox or label C#
问题描述
我正在使用带有SQL Server数据库的C#开发一个应用程序,所以想要在文本框或标签中显示数据,但要自动启动表单。
我希望他告诉每个插入的记录。但是想要自动完成而不按任何东西。
我可以按下按钮,以文字显示结果但自动加载表格,我没有得到>
有我的代码:
I'm developing an application using C # with SQL Server database, so want to show data in a text box or label, but carrying automatic starting of the form.
I want him to tell each record inserted. but want to do so automatically without pressing anything.
I can press the button, to show results in text but automatically load the form, I am not getting
there is my CODE:
SQL SERVER
1-
create proc dbo.[CountDate]
@Data_de_insc date
as
Begin
Select COUNT(*) as Clientes
from tb_FichaP where Data_de_insc = @Data_de_insc
end
====================================================
2-Select
create Proc [dbo].[sp_CountData_select]
as
Begin
Select Data_de_insc, COUNT(*) 'Clientes por Dia'
from tb_FichaP
group by Data_de_insc
order by Data_de_insc asc
BUtton保存并且show
BUtton Save and show
using (SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=db_Maried;Data Source=TOBE-ANGOLA-PC"))
{
SqlCommand cmd = new SqlCommand("CountData", conn);
cmd.Parameters.AddWithValue("@Data_de_insc", txtHora.Text/*timer*/);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
lblContador.Text = (string)cmd.ExecuteScalar().ToString();
conn.Close();
}
有人可以帮我吗
Can someone help me please
推荐答案
您缺少在storeprocedure中选择最新的ID。
You are missing to select latest id in you storeprocedure.
create proc dbo.[CountDate]
@Data_de_insc date
as
Begin
Select COUNT(*) as Clientes
from tb_FichaP where Data_de_insc = @Data_de_insc
SELECT SCOPE_IDENTITY();
end
它返回为其中的任何表生成的最后一个标识值当前会话和当前范围。
It returns the last identity value generated for any table in the current session and the current scope.
这篇关于如何在文本框或标签C#中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!