473,408 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to change data in grid after you change the SQL select for the data adapter

I have an ASP.net webform with a datagrid on it.

I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

The rest of the code in Sub Page_Load is

OleDbDataAdapter1.Fill(DsCategories1)
If Not IsPostBack Then
DataGrid1.DataBind()
End If

This works fine on the initial load of the the webform. If I want to
change the SQL command to load different data into the grid after the
form is loaded, and do that with a cmdButton, what code to I put under
the cmdButton to reload the webform or grid with the new sql select?

Jun 6 '06 #1
5 1705
Tom,

There is one command you should do at almost every end of a program.

DataGrid1.DataBind()

Strange that you have told that this should only be done in the non post
back situation.

\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

OleDbDataAdapter1.Fill(DsCategories1)
DataGrid1.DataBind()
///
Should do it in my opinion.

Cor
Jun 6 '06 #2
Thanks for your help, but that does not work. Isn't there some kind
of refresh or reload command that reloads the whole page? I know there
must be, but I can't find it.
Cor Ligthert [MVP] wrote:
Tom,

There is one command you should do at almost every end of a program.

DataGrid1.DataBind()

Strange that you have told that this should only be done in the non post
back situation.

\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

OleDbDataAdapter1.Fill(DsCategories1)
DataGrid1.DataBind()
///
Should do it in my opinion.

Cor


Jun 6 '06 #3
One more piece of information. Part of my problem seems to be that the
dataset is not getting reloaded by the SQL statement, because if move
the value of a field in the dataset to a label, I get the old value,
not the new value from the new select.

OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "
Label1.Text = DsCategories1.Tables(0).Rows(0).Item(1)


to******@gmail.com wrote:
Thanks for your help, but that does not work. Isn't there some kind
of refresh or reload command that reloads the whole page? I know there
must be, but I can't find it.
Cor Ligthert [MVP] wrote:
Tom,

There is one command you should do at almost every end of a program.

DataGrid1.DataBind()

Strange that you have told that this should only be done in the non post
back situation.

\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

OleDbDataAdapter1.Fill(DsCategories1)
DataGrid1.DataBind()
///
Should do it in my opinion.

Cor


Jun 6 '06 #4
> Thanks for your help, but that does not work. Isn't there some kind
of refresh or reload command that reloads the whole page? I know there
must be, but I can't find it.
Assuming of course that you have also set the datagrid.datasource to the
newly gotten dataset which you have before the fill have created new or have
cleared. (I would create new because that goes faster), thhis all before you
do the databind.

Something as
\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

DsCategories1 = New DsCatogeriesWhatever the class name is
'or
'DsCategories1.clear
OleDbDataAdapter1.Fill(DsCategories1)
mydatagrid.datasource = DsCategories1.tables(0).
DataGrid1.DataBind()
///
Cor



Cor Ligthert [MVP] wrote:
Tom,

There is one command you should do at almost every end of a program.

DataGrid1.DataBind()

Strange that you have told that this should only be done in the non post
back situation.

\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

OleDbDataAdapter1.Fill(DsCategories1)
DataGrid1.DataBind()
///
Should do it in my opinion.

Cor

Jun 6 '06 #5
Thanks you so much. The thing I was missing was the
DsCategories1.clear.

Cor Ligthert [MVP] wrote:
Thanks for your help, but that does not work. Isn't there some kind
of refresh or reload command that reloads the whole page? I know there
must be, but I can't find it.


Assuming of course that you have also set the datagrid.datasource to the
newly gotten dataset which you have before the fill have created new or have
cleared. (I would create new because that goes faster), thhis all before you
do the databind.

Something as
\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

DsCategories1 = New DsCatogeriesWhatever the class name is
'or
'DsCategories1.clear
OleDbDataAdapter1.Fill(DsCategories1)
mydatagrid.datasource = DsCategories1.tables(0).
DataGrid1.DataBind()
///
Cor



Cor Ligthert [MVP] wrote:
Tom,

There is one command you should do at almost every end of a program.

DataGrid1.DataBind()

Strange that you have told that this should only be done in the non post
back situation.

\\\
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

OleDbDataAdapter1.Fill(DsCategories1)
DataGrid1.DataBind()
///
Should do it in my opinion.

Cor


Jun 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pmud | last post by:
Hi, I have 4 columns in my sql database table. I added a data adapter , data set & a data grid to view this information. But the data grid is displaying those 4 columns TWICE , i.e in the data...
3
by: Andrew Dodgshun | last post by:
I have 2 grids - one shows a list of table names in a database and when you click on a table name the other grid dynamically populates the grid with the table contents. My problem is that I cannot...
16
by: Elena | last post by:
I am trying to name the columns in my datagrid. In VB6 it was one line of code: Datagrid1.columns(0).caption = "Item" I cannot seem to get this to work... Below is the code I'm using in...
12
by: Kimberley Wiggins | last post by:
Can someone please help me? I am still learning vb so this is fairly new. I have been chasing this problem for 3 days now and I think that I am ready to give up. Does anyone know how to make...
7
by: Wayne Wengert | last post by:
I am using VB with a Windows NET application. I have a datagrid in which the user can add rows using the "*" row. I want to detect whenever the user has added a row. I found the following code at...
9
by: Michael | last post by:
Hi, I have a large table. Normally, the user will need to see only the data from the past two years, but sometimes, they will need to go back further. I have a form with a datagrid, a...
9
by: Jenden0 | last post by:
I'm new to C# (and Microsoft in general) so this may be a simple problem, but I haven't been able to figure it out yet. I've got a database with a number of different tables and I want the user...
3
by: Ctal | last post by:
I have an app that populates several data tables on load. Each of these are bound to a datagrid. Above each datagrid I have several text boxes that display the data for the active row. There are...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.