将数据保存到gridview中 [英] Save data into gridview

查看:96
本文介绍了将数据保存到gridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友我正在创建表RowNo - >数字;名称 - > VARCHAR(50);地址 - > VARCHAR(50);城市 - > Varchar(50)



我在gridview中占用了所有这些字段,我想将此记录保存在数据库表中Emp所以请告诉我如何这样做。

Hi friends I am create table RowNo--> Numeric; Name-->Varchar(50); Address-->Varchar(50); City-->Varchar(50)

I am taking all this fields in gridview and i want to save this record in database table Emp So please tell me how to do it.

推荐答案

您无法将数据保存到gridview中。而是使用gridview显示数据。为此

首先编写一个存储过程,返回表emp中所有列的数据集。



创建过程getdetails

as

开始

select * from emp

end



然后取一个类文件并编写一个使用上述存储过程的方法。比如



公共数据集getdetails()

{

返回sqlhelper.executedataset(strcon,commandtype.storedprocedure,getdetails);

}



其中strcon是你的连接字符串



然后在代码隐藏文件中,通过为类创建对象并将返回的数据绑定到tour gridview来调用此方法。喜欢

cls obj = new cls;

数据集ds = obj.getdetails();

gridview1.datasource = ds;

gridview1.databind();



希望这会对你有所帮助。和类文件中的sqlhelper需要microsoft.applicationblocks.data dll
You cannot save the data into gridview. Rather you will display the data using gridview. For that
first Write a stored Procedure that returns dataset of the all the columns in the table emp.

Create Procedure getdetails
as
begin
select * from emp
end

Then Take a Class file and write a method that use the the above stored procedure.like

public dataset getdetails()
{
return sqlhelper.executedataset(strcon,commandtype.storedprocedure,"getdetails");
}

where strcon is your connection string

Then in the code behind file call this method by creating the object for the class and bind the returned data to tour gridview. like
cls obj=new cls;
dataset ds=obj.getdetails();
gridview1.datasource=ds;
gridview1.databind();

Hope this will help you. and sqlhelper above in class file needs microsoft.applicationblocks.data dll


嗨......

直接数据不能存储在gridview中是不可能的。但是第一个数据存储在数据库之后,存储的数据绑定到你需要的gridview是可能的。

所以,

>第一个数据存储到数据库中(使用插入查询)。 br />
>从数据库中检索数据(使用select *查询)和

>最后该数据绑定到gridview(使用gridview.bind())。



谢谢你。
Hi...
Directly data not store in gridview is not possible.but 1st data store in database after that, that stored data bind to ur required gridview is possible.
so,
>first data store in to data base(using insert query).
>retrieving data from data base(using select * query) and
>finally that data bind to gridview(using gridview.bind()).

thank u.


这篇关于将数据保存到gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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