使用a填充数据网格的最佳性能是什么代码 [英] What code has the best performance to populate a Data Grid with a

查看:65
本文介绍了使用a填充数据网格的最佳性能是什么代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MSDN杂志上尝试了一些代码示例,但现在我被卡住了。使用SP填充数据网格的最佳性能是什么代码?
?下面是代码I

,它可能正在填写填充数据网格的错误方法。我喜欢使用代码而不是服务器资源管理器。 (我在这篇文章中替换了

的sa密码。)

private void frmDealerSearch_Load(object sender,System.EventArgs e)

{


string sConnString =" Data

Source = db; Database = License; Integrated Security = False; User

ID = sa;密码=密码" ;;

string sProc =" prGet_DealerInfo";


使用(SqlConnection oCn = new

SqlConnection(sConnString))

{

使用(SqlCommand oCmd = new

SqlCommand(sProc,oCn))

$

oCn.Open();

oCmd.CommandType =

CommandType.StoredProcedure;


oDa.SelectCommand = oSelCmd;

dgDealerInfo.DataSource = oDa;


}

}

}


发生以下错误。

找不到类型或命名空间名称''oDa''(你错过了吗? />
使用指令或汇编引用?)


T.他的名字''oDa''在类或命名空间中不存在

''LicenseDealerSales.frmDealerSearch''


但你可能有更好的方法用于填充数据网格的代码。

I tried a sample of code in MSDN magazine, but now I''m stuck. What code has
the best performance to populate a Data Grid with a SP? Below is the code I
have, which might be completing the wrong way to populate a data grid. I
like using code and not the server explorer. (I replaced the sa password for
this post.)

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo.DataSource = oDa;

}
}
}

The following errors occur.
The type or namespace name ''oDa'' could not be found (are you missing a
using directive or an assembly reference?)

The name ''oDa'' does not exist in the class or namespace
''LicenseDealerSales.frmDealerSearch''

But you might have a better way to code to populate data grid.

推荐答案

你好,

oDA,是一个数据适配器,你必须要添加到表单中,我不知道你是否有b $ b ...或者你必须声明它...


Mike L写道:
hello,
oDA, is a data adapter, you must to add to the form, i dont know if you have
it... or you must to declare it...

"Mike L" wrote:
我在MSDN杂志上尝试了一些代码示例,但现在我被卡住了。什么代码具有用SP填充数据网格的最佳性能?下面是我的代码,它可能正在填写填充数据网格的错误方法。我喜欢使用代码而不是服务器资源管理器。 (我替换了这篇帖子的sa密码。)

private void frmDealerSearch_Load(object sender,System.EventArgs e)


string sConnString =" Data
Source = db; Database = License; Integrated Security = False; User
ID = sa; password = password" ;;
string sProc =" prGet_DealerInfo" ;;

使用(SqlConnection oCn = new
SqlConnection(sConnString))
{
使用(SqlCommand oCmd = new
SqlCommand(sProc,oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo.DataSource = oDa ;

}
}

发生以下错误。
无法找到类型或命名空间名称''oDa''(你错过了吗?) >使用指令或汇编引用?)

类或命名空间中不存在oDa这个名称
''LicenseDealerSales.frmDealerSearch''

>但是你可能有更好的方法来编码填充数据网格。
I tried a sample of code in MSDN magazine, but now I''m stuck. What code has
the best performance to populate a Data Grid with a SP? Below is the code I
have, which might be completing the wrong way to populate a data grid. I
like using code and not the server explorer. (I replaced the sa password for
this post.)

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo.DataSource = oDa;

}
}
}

The following errors occur.
The type or namespace name ''oDa'' could not be found (are you missing a
using directive or an assembly reference?)

The name ''oDa'' does not exist in the class or namespace
''LicenseDealerSales.frmDealerSearch''

But you might have a better way to code to populate data grid.






所有,你应该检查这是否是一个回发,你只需绑定

网格如果它不是回发

你需要以后的数据吗?

如果是这样你应该将它存储在数据集中,


否则只需使用DataReader,如下所示:


private void frmDealerSearch_Load(object sender,System.EventArgs e)

{


if(!IsPostBack)

{

string sConnStr ing =" Data

Source = db; Database = License; Integrated Security = False; User

ID = sa; password = password" ;;

string sProc =" prGet_DealerInfo";


使用(SqlConnection oCn = new

SqlConnection(sConnString))

{

使用(SqlCommand oCmd = new

SqlCommand(sProc,oCn))

{

oCn.Open( );

oCmd.CommandType =

CommandType.StoredProcedure;


SqlDataReader reader = oCmd.ExecuteReader();


datagrid.DataSource = reader;

datagrid.DataBind();

reader.Close();

}

}

}


}


欢呼,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通部


" Mike L" <钙*** @ nospam.nospam>在消息中写道

新闻:02 ********************************** @ microsof t.com ...
Hi,

first of all, you should check if this is a postback or not, you just bind
the grid if it''s not a postback
do you need the data for later?
If so you should store it in a dataset,

otherwise just use a DataReader as shown below:

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

if (!IsPostBack )
{
string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

SqlDataReader reader = oCmd.ExecuteReader();

datagrid.DataSource = reader;
datagrid.DataBind();
reader.Close();

}
}
}

}

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike L" <Ca***@nospam.nospam> wrote in message
news:02**********************************@microsof t.com...
我在MSDN杂志上尝试了一些代码示例,但现在我被卡住了。什么代码
具有用SP填充数据网格的最佳性能?下面是我有的代码,它可能正在填写填充数据网格的错误方法。我喜欢使用代码而不是服务器资源管理器。 (我替换了这个帖子的sa密码


private void frmDealerSearch_Load(object sender,System.EventArgs e)


/> string sConnString =" Data
Source = db; Database = License; Integrated Security = False; User
ID = sa; password = password" ;;
string sProc =" prGet_DealerInfo" ;

使用(SqlConnection oCn = new
SqlConnection(sConnString))
{
使用(SqlCommand oCmd = new
SqlCommand(sProc,oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo .DataSource = oDa;

}
}

发生以下错误。
无法找到类型或命名空间名称''oDa''(你错过了吗?) >使用指令或汇编引用?)

类或命名空间中不存在oDa这个名称
''LicenseDealerSales.frmDealerSearch''

>但是你可能有更好的方法来编码填充数据网格。
I tried a sample of code in MSDN magazine, but now I''m stuck. What code
has
the best performance to populate a Data Grid with a SP? Below is the code
I
have, which might be completing the wrong way to populate a data grid. I
like using code and not the server explorer. (I replaced the sa password
for
this post.)

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo.DataSource = oDa;

}
}
}

The following errors occur.
The type or namespace name ''oDa'' could not be found (are you missing a
using directive or an assembly reference?)

The name ''oDa'' does not exist in the class or namespace
''LicenseDealerSales.frmDealerSearch''

But you might have a better way to code to populate data grid.



谢谢,这就是我需要的。


要在将来保存帖子,将它保存到数据集的代码是什么?


另外,不确定你说的回发是什么,这不是网页,但在域中运行的
客户端/服务器应用程序。


Ignacio Machin(.NET / C#MVP)"写道:
Thanks, that''s what I needed.

To save a post in the future, what is the code to save it to a dataset?

Also, not sure what your talking about postback, this is not web page but a
client/server application run in the domain.

"Ignacio Machin ( .NET/ C# MVP )" wrote:


首先,你应该检查这是否是回发,你只需要绑定网格如果它'不是回发

你需要以后的数据吗?
如果是这样的话你应该将它存储在数据集中,

否则只需使用DataReader如下所示:

private void frmDealerSearch_Load(object sender,System.EventArgs e)
{

if(!IsPostBack)
{
string sConnString =" Data
Source = db; Database = License; Integrated Security = False; User
ID = sa; password = password" ;;
string sProc =" prGet_DealerInfo" ;; <登记/>
用(SqlConnection的OCN =新
的SqlConnection(sConnString))
{
用(的SqlCommand OCMD =新
的SqlCommand(SPROC,OCN))<无线电通信/> {
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

SqlDataReader reader = oCmd.ExecuteReader();

datagrid.DataSource = reader;
datagrid.DataBind();
reader.Close();

}
}
}

欢呼,

- Ignacio Machin,
ignacio.machin at dot.state.fl.us
佛罗里达州的部门交通

Mike L <钙*** @ nospam.nospam>在消息中写道
新闻:02 ********************************** @ microsof t.com。 ..
Hi,

first of all, you should check if this is a postback or not, you just bind
the grid if it''s not a postback
do you need the data for later?
If so you should store it in a dataset,

otherwise just use a DataReader as shown below:

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

if (!IsPostBack )
{
string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

SqlDataReader reader = oCmd.ExecuteReader();

datagrid.DataSource = reader;
datagrid.DataBind();
reader.Close();

}
}
}

}

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike L" <Ca***@nospam.nospam> wrote in message
news:02**********************************@microsof t.com...
我在MSDN杂志上尝试了一些代码示例,但现在我被卡住了。什么代码
具有用SP填充数据网格的最佳性能?下面是我有的代码,它可能正在填写填充数据网格的错误方法。我喜欢使用代码而不是服务器资源管理器。 (我替换了这个帖子的sa密码


private void frmDealerSearch_Load(object sender,System.EventArgs e)


/> string sConnString =" Data
Source = db; Database = License; Integrated Security = False; User
ID = sa; password = password" ;;
string sProc =" prGet_DealerInfo" ;

使用(SqlConnection oCn = new
SqlConnection(sConnString))
{
使用(SqlCommand oCmd = new
SqlCommand(sProc,oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo .DataSource = oDa;

}
}

发生以下错误。
无法找到类型或命名空间名称''oDa''(你错过了吗?) >使用指令或汇编引用?)

类或命名空间中不存在oDa这个名称
''LicenseDealerSales.frmDealerSearch''

>但是你可能有更好的方法来编码填充数据网格。
I tried a sample of code in MSDN magazine, but now I''m stuck. What code
has
the best performance to populate a Data Grid with a SP? Below is the code
I
have, which might be completing the wrong way to populate a data grid. I
like using code and not the server explorer. (I replaced the sa password
for
this post.)

private void frmDealerSearch_Load(object sender, System.EventArgs e)
{

string sConnString = "Data
Source=db;Database=License;Integrated Security=False;User
ID=sa;password=password";
string sProc = "prGet_DealerInfo";

using (SqlConnection oCn = new
SqlConnection(sConnString))
{
using (SqlCommand oCmd = new
SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType =
CommandType.StoredProcedure;

oDa.SelectCommand = oSelCmd;
dgDealerInfo.DataSource = oDa;

}
}
}

The following errors occur.
The type or namespace name ''oDa'' could not be found (are you missing a
using directive or an assembly reference?)

The name ''oDa'' does not exist in the class or namespace
''LicenseDealerSales.frmDealerSearch''

But you might have a better way to code to populate data grid.




这篇关于使用a填充数据网格的最佳性能是什么代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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