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. 9 3291
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: 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.
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... 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.
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: 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...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.
I'm getting an error with your code.
(141): 'System.Windows.Forms.DataGrid' does not contain a definition for
'DataBind'
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;
SqlDataReader reader = oCmd.ExecuteReader();
dgDealerInfo.DataSource = reader;
dgDealerInfo.DataBind();
reader.Close();
}
}
}
"Ignacio Machin ( .NET/ C# MVP )" wrote: 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...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.
Hi Cadel,
Thanks for your feedback.
Actually, "Ignacio Machin \( .NET/ C# MVP \)" assumes that you used Asp.net
DataGrid, so the code snippet he provided is Asp.net specific. For Winform
datagrid, there is no postback concept, we can just use the SqlDataAdapter
to fill a DataSet, then set the DataSet as the DataSource of DataGrid
control, and no DataBind method needed.
Hope this helps
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
I'm getting an error "System.Exception: Complex DataBinding accepts as a data
source either an IList or an IListSource" on dgDealerInfo.DataSource = reader;
Here is my code.
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;
oCmd.Parameters.Add("@sDealerNum", SqlDbType.NChar, 6);
oCmd.Parameters["@sDealerNum"].Value = "462004";
SqlDataReader reader = oCmd.ExecuteReader();
dgDealerInfo.DataSource = reader;
reader.Close();
}
}
""Jeffrey Tan[MSFT]"" wrote: Hi Cadel,
Thanks for your feedback.
Actually, "Ignacio Machin \( .NET/ C# MVP \)" assumes that you used Asp.net DataGrid, so the code snippet he provided is Asp.net specific. For Winform datagrid, there is no postback concept, we can just use the SqlDataAdapter to fill a DataSet, then set the DataSet as the DataSource of DataGrid control, and no DataBind method needed.
Hope this helps =========================================== Thank you for your patience and cooperation. If you have any questions or concerns, please feel free to post it in the group. I am standing by to be of assistance.
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
I'm getting an error "System.Exception: Complex DataBinding accepts as a data
source either an IList or an IListSource" on dgDealerInfo.DataSource = reader;
Here is my code.
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;
oCmd.Parameters.Add("@sDealerNum", SqlDbType.NChar, 6);
oCmd.Parameters["@sDealerNum"].Value = "462004";
SqlDataReader reader = oCmd.ExecuteReader();
dgDealerInfo.DataSource = reader;
reader.Close();
}
}
""Jeffrey Tan[MSFT]"" wrote: Hi Cadel,
Thanks for your feedback.
Actually, "Ignacio Machin \( .NET/ C# MVP \)" assumes that you used Asp.net DataGrid, so the code snippet he provided is Asp.net specific. For Winform datagrid, there is no postback concept, we can just use the SqlDataAdapter to fill a DataSet, then set the DataSet as the DataSource of DataGrid control, and no DataBind method needed.
Hope this helps =========================================== Thank you for your patience and cooperation. If you have any questions or concerns, please feel free to post it in the group. I am standing by to be of assistance.
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Hi Cadel,
Thanks for your feedback.
Yes, winform databinding is a 2 way databinding, it can not accept
SqlDataReader as the datasource, so you can not use "Ignacio Machin \(
NET/ C# MVP \)"'s code snippet, actually this code snippet is only for
Asp.net DataGrid.
For winform databinding, we should use a SqlDataAdapter to read the
database, then use SqlDataAdapter.Fill method to fill a dataset. At last,
we should set DataSet as the datasource of winform DataGrid control. Like
the sample code below:
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;
DataSet ds=new DataSet();
oDa.Fill(ds);
dgDealerInfo.DataSource = ds;
}
}
Note: I just add a little modification to your original code snippet in the
first post. I assume oDa is the SqlDataAdapter.
Hope this helps
================================================== ======
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Hi Cadel,
Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Mullins |
last post by:
I'm building a GUI that needs to be able to view a large amount of text
arranged in rows. Large being anywhere from a few hundred lines through a
few hundred thousand. I need a way to "cap" the max...
|
by: Snake |
last post by:
I have a vb .net program which fills a data grid upon form load from an
acccess database. This works great. Now, I have to add a combo box and use
it to alter the underlying sql statement and...
|
by: Anita C |
last post by:
Hi,
How do I associate or map a specific column in a datatable to a particular
element present in an xml document - to read into a datatable as well as
write from the datatable to the xml element?...
|
by: Mountain Bikn' Guy |
last post by:
I need some advice on this. I am working on a fairly complex calculator app
(C#) with lots of functions (and these functions in turn use math functions
from an unmanaged C DLL). A calculation takes...
|
by: Carlos Lozano |
last post by:
Hi,
I have to populate a grid from a data table. I do not know how big the table
can grow and would like to plan ahead to avoid problems.
I will give the user options to filter the data to show...
|
by: Sivaprasad |
last post by:
Hello,
Can anybody suggest me, which is the best grid that can be used in ASP.Net.
The main functionality I'm looking for is
I shoud be able to do heirarchical view of data.
Need to do a row...
|
by: Mr Newbie |
last post by:
Hi,
I have tables which are going to display working hours ( Timesheet ) I was
wondering the best way to total them. The grid is filled with data from a
query bound to a table. Does anyone have...
|
by: Rich |
last post by:
Hello,
I have a search application to search data in tables in a database (3 sql
server tables). I populate 2 comboboxes with with data from each table. One
combobox will contain unique...
|
by: John Straumann |
last post by:
Hello all:
I am trying to populate a GridView with data being read from a call to a web
service. I have seen plenty of examples that simply execute a SQL data
reader, set the Grid data source to...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |