在ASP.NET中使用SQL从DataBAse中检索数据 [英] Retreive Data From DataBAse Using SQL in ASP.NET

查看:96
本文介绍了在ASP.NET中使用SQL从DataBAse中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经使用ms访问在单独的网页中创建了2个表.......现在,我想在3页的表中显示具有相同字段的值,然后单击2页上的保存按钮..... ...

在此先感谢

Hi,
i have created 2 tables in a separate web pages using ms access.......Now i want to display the values in the 3 table having same fields , after i click the save button on the 2 page ........

Thanks in advance

推荐答案

基础ADO.NET,该文档已被很好地记录.

Basic ADO.NET that is extremely well documented.

using(SqlConnection Conn = new SqlConnection(...))
using(SqlCommand cmd = new SqlCommand("...", Conn))
{
   DataTable dt = new DataTable();
   Conn.Open();
   dt.Load(cmd.ExecuteReader());

   Grid.DataSource = dt;
   Grid.DataBind();
}


您将使用InsertTrigger来解决此问题.我正在向您展示一个例子,我认为它将对您有帮助

you will use InsertTrigger for sort out this problem. i am showing you an example i think it will help you

CREATE TRIGGER trgAfterInsert ON [dbo].[Employee_Test]
FOR INSERT
AS
    declare @empid int;
    declare @empname varchar(100);
    declare @empsal decimal(10,2);
    declare @audit_action varchar(100);

    select @empid=i.Emp_ID from inserted i;
    select @empname=i.Emp_Name from inserted i;
    select @empsal=i.Emp_Sal from inserted i;
    set @audit_action='Inserted Record -- After Insert Trigger.';

    insert into Employee_Test_Audit
           (Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
    values(@empid,@empname,@empsal,@audit_action,getdate());

    PRINT 'AFTER INSERT trigger fired.'
GO



在sql管理中.单击表(在您的情况下为table2),然后单击触发器,然后右键单击它,然后单击创建触发器,然后根据需要创建触发器.之后,当您在表2中插入数据时,该数据将自动复制到表3中.

如果可以解决此问题,则将其标记为答案.



in sql management. click on table (in your case table2)then then click on trigger and now right click on it and click on create trigger then create your trigger as per your requirement. after that when you insert data in table2 then this data automatically copy in table 3.

if it will solve this problem then mark it as answer.


您可以保存数据,然后调用此函数,该函数将填充第三个表...
或者您可以在数据库中编写触发器,然后将此表与要填充数据的表形式绑定起来...
非常简单...


编写一个选择数据的过程.保存记录后,对保存按钮调用此过程....
you can save the data and after this call a function which populate the third table ...
or you can write triger in the data base and bind this table with the table form which you want to populate the data ...
its so easy ...


write a procedure which select the data. and call this procedure against the save button after saving the record ....


这篇关于在ASP.NET中使用SQL从DataBAse中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆