Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

Sunday, February 19, 2012

GridView...Problem

I m creating the project in asp.net using c# and vb languages in 2005.

I have used the asp standard controls(with table<td><tr>) and gridview to design the form.

I m using sqldatasource to insert and update data from sql server 2005.

I have written the following code

<script runat="server">
Private Sub Page_Load()
If Not Request.Form("SUBMIT") Is Nothing Then
srccompany.Insert()
End If
End Sub
</script>

<asp:SqlDataSource
id="srccompany"
SelectCommand="SELECT * FROM companymaster"
InsertCommand="INSERT companymaster(companyname)
VALUES (@.companyname)"

UpdateCommand="UPDATE companymaster SET companyname=@.companyname WHERE companyid=1"
DeleteCommand="DELETE companymaster WHERE companyname=@.companyname"
ConnectionString="<%$ ConnectionStrings:companymaster %>"
Runat="server">
</asp:SqlDataSource>

<asp:GridView
id="GridCompanyMaster"
DataSourceID="srccompany"
Runat="server" />

Please help me to insert the data in sql server.i m not been able to insert the data is there any problem in coding..

Also i m not been able to edit the data and store back to sql server.

Only i can do is i can view the contents in gridview

Please give me some tips

Try writing:

insertinto

GridView, XML, and .NET 2005 Application

Hello, I'm in the processing of learning .NET 2005 and an trying to rewrite
a simple command line application that I wrote a couple years ago. I have
the following requirements:
1) Read an XML file that I create with a list of .EXE and .DLL files.
2) Scan a directory based on the path stored within the XML file and extract
the production version information
3) Add the Path, Filename and version information to a GridView control.
Now I have item #3 working today which displays output to screen using
console.write.
Question 1:
How can I add headers to a datagrid and update with my own information based
on me scanning a directory?
Question 2:
My application today reads the file path information, etc., from SQL Server
and then scans the directory for the version information. I would like to
instead use an XML file to contain this information instead of SQL Server.
This way I can use ClickOnce easily deploy my application without having a
SQL Server requirement. Most of my updates will be done to the XML file
only, so I would simply like to republish my ClickOnce to have user
redownload new XML file.
What is the best way for me to create an XML file of my data that can be
maintained? I have columsn such as:
1) Filename
2) Path of file
3) Description
4) Shortname of file
Each row within the XML will be unique. I need a way that I can easily
update/create this file. I currently have about 200 rows in SQL that I need
to get into my XML file. I really do not want to retype all the
information, but I can if I have to.
Any help or direction with this would be appreciated.
You can save a DataSet as XML.
And something else you might want to think about. If the data displayed is
static, not requiring any user interaction, you might want to think about
optimizing your app by using an XSL transform to create the data in HTML in
the page, rather than a DataGrid. You can create an XSL style sheet, and use
an Xml WebControl to display it in any format you choose (as HTML).
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
"dm1608" <dm1608@.spam.net> wrote in message
news:u3Uq5nU9FHA.1148@.tk2msftngp13.phx.gbl...
> Hello, I'm in the processing of learning .NET 2005 and an trying to
> rewrite a simple command line application that I wrote a couple years ago.
> I have the following requirements:
> 1) Read an XML file that I create with a list of .EXE and .DLL files.
> 2) Scan a directory based on the path stored within the XML file and
> extract the production version information
> 3) Add the Path, Filename and version information to a GridView control.
>
> Now I have item #3 working today which displays output to screen using
> console.write.
> Question 1:
> How can I add headers to a datagrid and update with my own information
> based on me scanning a directory?
> Question 2:
> My application today reads the file path information, etc., from SQL
> Server and then scans the directory for the version information. I would
> like to instead use an XML file to contain this information instead of SQL
> Server. This way I can use ClickOnce easily deploy my application without
> having a SQL Server requirement. Most of my updates will be done to the
> XML file only, so I would simply like to republish my ClickOnce to have
> user redownload new XML file.
> What is the best way for me to create an XML file of my data that can be
> maintained? I have columsn such as:
> 1) Filename
> 2) Path of file
> 3) Description
> 4) Shortname of file
> Each row within the XML will be unique. I need a way that I can easily
> update/create this file. I currently have about 200 rows in SQL that I
> need to get into my XML file. I really do not want to retype all the
> information, but I can if I have to.
> Any help or direction with this would be appreciated.
>
>
>
|||Thanks for the reply, Keven.
I'm trying to do away with using SQL Server. If I use the SaveToXML option
of ADO.NET, is the XML file the is created something that can easily be
maintained going forward? I guess I cannot control the output or format of
the XML file, so that is why I'm thinking it may not be what I want.
Opinions?
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:%23WA93ra9FHA.3876@.TK2MSFTNGP09.phx.gbl...
> You can save a DataSet as XML.
> And something else you might want to think about. If the data displayed is
> static, not requiring any user interaction, you might want to think about
> optimizing your app by using an XSL transform to create the data in HTML
> in the page, rather than a DataGrid. You can create an XSL style sheet,
> and use an Xml WebControl to display it in any format you choose (as
> HTML).
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> If you push something hard enough,
> it will fall over.
> - Fudd's First Law of Opposition
> "dm1608" <dm1608@.spam.net> wrote in message
> news:u3Uq5nU9FHA.1148@.tk2msftngp13.phx.gbl...
>
|||I don't think it s a good idea to replace the database with an XML file. You
will loose all the benefits of concurrency control, backup/restore,
maintenance etc that the database provides you with.
You can store your XML in the database though either shredded (if it is
relational in nature) or natively...
Best regards
Michael
"dm1608" <dm1608@.spam.net> wrote in message
news:es1WSjb9FHA.2716@.TK2MSFTNGP11.phx.gbl...
> Thanks for the reply, Keven.
> I'm trying to do away with using SQL Server. If I use the SaveToXML
> option of ADO.NET, is the XML file the is created something that can
> easily be maintained going forward? I guess I cannot control the output
> or format of the XML file, so that is why I'm thinking it may not be what
> I want.
> Opinions?
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:%23WA93ra9FHA.3876@.TK2MSFTNGP09.phx.gbl...
>

GridView, XML, and .NET 2005 Application

Hello, I'm in the processing of learning .NET 2005 and an trying to rewrite
a simple command line application that I wrote a couple years ago. I have
the following requirements:
1) Read an XML file that I create with a list of .EXE and .DLL files.
2) Scan a directory based on the path stored within the XML file and extract
the production version information
3) Add the Path, Filename and version information to a GridView control.
Now I have item #3 working today which displays output to screen using
console.write.
Question 1:
How can I add headers to a datagrid and update with my own information based
on me scanning a directory?
Question 2:
My application today reads the file path information, etc., from SQL Server
and then scans the directory for the version information. I would like to
instead use an XML file to contain this information instead of SQL Server.
This way I can use ClickOnce easily deploy my application without having a
SQL Server requirement. Most of my updates will be done to the XML file
only, so I would simply like to republish my ClickOnce to have user
redownload new XML file.
What is the best way for me to create an XML file of my data that can be
maintained? I have columsn such as:
1) Filename
2) Path of file
3) Description
4) Shortname of file
Each row within the XML will be unique. I need a way that I can easily
update/create this file. I currently have about 200 rows in SQL that I need
to get into my XML file. I really do not want to retype all the
information, but I can if I have to.
Any help or direction with this would be appreciated.You can save a DataSet as XML.
And something else you might want to think about. If the data displayed is
static, not requiring any user interaction, you might want to think about
optimizing your app by using an XSL transform to create the data in HTML in
the page, rather than a DataGrid. You can create an XSL style sheet, and use
an Xml WebControl to display it in any format you choose (as HTML).
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
"dm1608" <dm1608@.spam.net> wrote in message
news:u3Uq5nU9FHA.1148@.tk2msftngp13.phx.gbl...
> Hello, I'm in the processing of learning .NET 2005 and an trying to
> rewrite a simple command line application that I wrote a couple years ago.
> I have the following requirements:
> 1) Read an XML file that I create with a list of .EXE and .DLL files.
> 2) Scan a directory based on the path stored within the XML file and
> extract the production version information
> 3) Add the Path, Filename and version information to a GridView control.
>
> Now I have item #3 working today which displays output to screen using
> console.write.
> Question 1:
> How can I add headers to a datagrid and update with my own information
> based on me scanning a directory?
> Question 2:
> My application today reads the file path information, etc., from SQL
> Server and then scans the directory for the version information. I would
> like to instead use an XML file to contain this information instead of SQL
> Server. This way I can use ClickOnce easily deploy my application without
> having a SQL Server requirement. Most of my updates will be done to the
> XML file only, so I would simply like to republish my ClickOnce to have
> user redownload new XML file.
> What is the best way for me to create an XML file of my data that can be
> maintained? I have columsn such as:
> 1) Filename
> 2) Path of file
> 3) Description
> 4) Shortname of file
> Each row within the XML will be unique. I need a way that I can easily
> update/create this file. I currently have about 200 rows in SQL that I
> need to get into my XML file. I really do not want to retype all the
> information, but I can if I have to.
> Any help or direction with this would be appreciated.
>
>
>|||Thanks for the reply, Keven.
I'm trying to do away with using SQL Server. If I use the SaveToXML option
of ADO.NET, is the XML file the is created something that can easily be
maintained going forward? I guess I cannot control the output or format of
the XML file, so that is why I'm thinking it may not be what I want.
Opinions?
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:%23WA93ra9FHA.3876@.TK2MSFTNGP09.phx.gbl...
> You can save a DataSet as XML.
> And something else you might want to think about. If the data displayed is
> static, not requiring any user interaction, you might want to think about
> optimizing your app by using an XSL transform to create the data in HTML
> in the page, rather than a DataGrid. You can create an XSL style sheet,
> and use an Xml WebControl to display it in any format you choose (as
> HTML).
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> If you push something hard enough,
> it will fall over.
> - Fudd's First Law of Opposition
> "dm1608" <dm1608@.spam.net> wrote in message
> news:u3Uq5nU9FHA.1148@.tk2msftngp13.phx.gbl...
>|||I don't think it s a good idea to replace the database with an XML file. You
will loose all the benefits of concurrency control, backup/restore,
maintenance etc that the database provides you with.
You can store your XML in the database though either shredded (if it is
relational in nature) or natively...
Best regards
Michael
"dm1608" <dm1608@.spam.net> wrote in message
news:es1WSjb9FHA.2716@.TK2MSFTNGP11.phx.gbl...
> Thanks for the reply, Keven.
> I'm trying to do away with using SQL Server. If I use the SaveToXML
> option of ADO.NET, is the XML file the is created something that can
> easily be maintained going forward? I guess I cannot control the output
> or format of the XML file, so that is why I'm thinking it may not be what
> I want.
> Opinions?
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:%23WA93ra9FHA.3876@.TK2MSFTNGP09.phx.gbl...
>

GridView wont delete or update

I have had this problem before but it turned out to be dodgy SQL created by the wizard. Doesn't seem to be the case this time.

The following does a postback but makes no changes.

1<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ehlConnectionString %>"2DeleteCommand="DELETE FROM [tblSubRegions] WHERE [SubRegionID] = ?"3InsertCommand="INSERT INTO [tblSubRegions] ([SubRegionID], [RegionID], [SubRegionName]) VALUES (?, ?, ?)"4ProviderName="<%$ ConnectionStrings:ehlConnectionString.ProviderName %>"5SelectCommand="SELECT tblSubRegions.SubRegionID, tblSubRegions.RegionID, tblSubRegions.SubRegionName, tblRegions.RegionName FROM (tblSubRegions INNER JOIN tblRegions ON tblSubRegions.RegionID = tblRegions.RegionID) WHERE (tblSubRegions.RegionID = ?) ORDER BY tblSubRegions.SubRegionName"6UpdateCommand="UPDATE [tblSubRegions] SET [RegionID] = ?, [SubRegionName] = ? WHERE [SubRegionID] = ?">78<DeleteParameters>9 <asp:Parameter Name="SubRegionID" Type="Int32" />10</DeleteParameters>1112<UpdateParameters>13<asp:Parameter Name="RegionID" Type="Int32" />14<asp:Parameter Name="SubRegionName" Type="String" />15<asp:Parameter Name="SubRegionID" Type="Int32" />16</UpdateParameters>1718<SelectParameters>19<asp:ControlParameter ControlID="dropRegions" Name="RegionID" PropertyName="SelectedValue" Type="Int32" />20</SelectParameters>2122<InsertParameters>23<asp:Parameter Name="SubRegionID" Type="Int32" />24<asp:Parameter Name="RegionID" Type="Int32" />25<asp:Parameter Name="SubRegionName" Type="String" />26</InsertParameters>2728</asp:SqlDataSource>29303132<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ehlConnectionString %>"33ProviderName="<%$ ConnectionStrings:ehlConnectionString.ProviderName %>"34SelectCommand="SELECT [RegionID], [RegionName] FROM [tblRegions]">3536</asp:SqlDataSource>37383940<asp:DropDownList id="dropStates" runat="server" OnSelectedIndexChanged="dropStates_SelectedIndexChanged" AutoPostBack="True">41</asp:DropDownList>4243<asp:DropDownList id="dropRegions" runat="server" OnSelectedIndexChanged="dropRegions_SelectedIndexChanged" AutoPostBack="True">44</asp:DropDownList>45464748 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"49 AutoGenerateColumns="False" EnableViewState=false Width="100%" DataSourceID="SqlDataSource1">50 <Columns>51 <asp:TemplateField HeaderText="SubRegionName" SortExpression="SubRegionName">52 <EditItemTemplate>53 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"54 DataTextField="RegionName" DataValueField="RegionID" SelectedValue='<%# Bind("RegionID") %>'>55 </asp:DropDownList>56 </EditItemTemplate>57 <ItemTemplate>58 <asp:Label ID="Label1" runat="server" Text='<%# Bind("SubRegionName") %>'></asp:Label>59 </ItemTemplate>60 </asp:TemplateField>61 <asp:BoundField DataField="RegionName" HeaderText="RegionName" SortExpression="RegionName" />62 <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />63 </Columns>64 </asp:GridView>

Thanks in advance.

Shaun

You need to set DataKeyNames="yourprimarykey"

GridView via SQLDataSource and Stored Procedure

Help!

I am trying to fill my datagrid using the SQLDataSource, using a stored procedure.

The stored procedure expects a parameter which I can collect via the querystring, or a string. How can I pass the parameter through the SQLDatasSource?

My SQLDataSource is SQLData1. I already have:

SQLData1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
SQLData1.SelectCommand = "dbo.get_players"

Thanks in advance,

Karls

I think you need SQLData1.SelectParameters property, take a look at this article:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.selectparameters(VS.80).aspx

|||Thanks,

I found it after I posted the question.

Cheers

GridView update, with SqlDataSource UpdateCommand set from Code-behind. (C#)

Hi all

I have a GridView on an aspx page, that is enabled for editing, deletion and sorting.

In the Page_Load event of the aspx page, i add a SqlDataSource to the page, and bind the source to the GridView.

When i click the update, or delete button, it makes a PostBack, but nothing is affected. I'm sure this has got something to do with the parameters.

First, i tried having the GridView.AutoGenerateColumns set to True. I have also tried adding the columns manually, but no affect here either.

The code for setting the commands, and adding the SqlDataSource to the page are as follows:

string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
string selectCommand = "SELECT * FROM rammekategori";

SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);
ds.ID = "RammeKategoriDS";
ds.UpdateCommand = "UPDATE rammekategori SET Kategoribeskrivelse = @.Kategoribeskrivelse WHERE (Kategorinavn = @.Kategorinavn)";
ds.DeleteCommand = "DELETE FROM rammekategori WHERE (Kategorinavn = @.Kategorinavn)";

Parameter Kategorinavn = new Parameter("Kategorinavn", TypeCode.String);
Parameter Kategoribeskrivelse = new Parameter("Kategoribeskrivelse", TypeCode.String);
ds.UpdateParameters.Add(Kategorinavn);
ds.UpdateParameters.Add(Kategoribeskrivelse);
ds.DeleteParameters.Add(Kategorinavn);

Page.Controls.Add(ds);

SqlDataSource m_SqlDataSource = Page.FindControl("RammeKategoriDS") as SqlDataSource;

if (m_SqlDataSource != null)
{
this.gvRammeKategorier.DataSourceID = m_SqlDataSource.ID;
}

As mentioned - no affect at all!

Thanks in advance - MartinHN

It turned out, that the SQL-statements where wrong. I got it all to work now, by using a ?-mark, instead of @.Parametername in the SQL.

So this works:

string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
string selectCommand = "SELECT * FROM rammekategori";

SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);
ds.ID = "RammeKategoriDS";
ds.UpdateCommand = "UPDATE rammekategori SET Kategoribeskrivelse = ? WHERE Kategorinavn = ?";
ds.DeleteCommand = "DELETE FROM rammekategori WHERE Kategorinavn = ?";

Parameter Kategorinavn = new Parameter("Kategorinavn");
Parameter Kategoribeskrivelse = new Parameter("Kategoribeskrivelse");
ds.UpdateParameters.Add(Kategorinavn);
ds.UpdateParameters.Add(Kategoribeskrivelse);
ds.DeleteParameters.Add(Kategorinavn);

Page.Controls.Add(ds);

SqlDataSource m_SqlDataSource = Page.FindControl("RammeKategoriDS") as SqlDataSource;

if (m_SqlDataSource != null)
{
this.gvRammeKategorier.DataSourceID = m_SqlDataSource.ID;
}

I was working on a MySQL server, and not a MS-SQL server, as I normally do...

|||Is there any particular reason why you are adding the SqlDataSource dynamically rather than declaring it in your .aspx code?|||

>>Is there any particular reason why you are adding the SqlDataSource dynamically rather than declaring it in your .aspx code?

Yes - there sure is. I want to define alle data-access information, such as SQL-statements in a lower-tier-layer, so i would be able to remove the GUI, and change it with another GUI. It just gives a better architecture to it...

|||

martinhn wrote:

Yes - there sure is. I want to define alle data-access information, such as SQL-statements in a lower-tier-layer, so i would be able to remove the GUI, and change it with another GUI. It just gives a better architecture to it...

It sounds like the ObjectDataSource is more suited for what you are trying to do.

HTH,
Ryan

GridView UPDATE Problem

Hi Gutys

I am having problem with my UPDATE in GridView, it is saying that I have too many argument, I don't
This happens when I click the UpdateCommand in GRIDVIEW

Procedure or function UpdateCountry has too many arguments specified.

<asp:SqlDataSource ID="mySqlDataSource" Runat="server"
SelectCommandType="StoredProcedure" SelectCommand="ShowCountry"
UpdateCommandType="StoredProcedure" UpdateCommand="UpdateCountry"
ConnectionString="<%$ ConnectionStrings:ConnString %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="CountryName"></asp:Parameter>
<asp:Parameter Type="String" Name="CountryID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource
Just In case these are my Stored Procedures
**************************************************************************
CREATE PROCEDURE [dbo].[UpdateCountry]
@.CountryName varchar(50),
@.CountryID varchar(50)
AS
UPDATE EkeanyanwuO.tCountry SET [CountryName] = @.CountryName WHERE [CountryID] = @.CountryID
GO
************************************************************************************
CREATE PROCEDURE [dbo].[ShowCountry] AS
SELECT TOP 100 PERCENT EkeanyanwuO.tIMSREGION.ImsRegionName AS ImsRegionName, EkeanyanwuO.tCountry.CountryName AS CountryName,
EkeanyanwuO.tIMSREGION.ImsRegionID AS ImsRegionID, EkeanyanwuO.tCountry.CountryID AS CountryID
FROM EkeanyanwuO.tCountry INNER JOIN
EkeanyanwuO.tIMSREGION ON EkeanyanwuO.tCountry.ImsRegionID = EkeanyanwuO.tIMSREGION.ImsRegionID
ORDER BY EkeanyanwuO.tCountry.CountryName
GO
************************************************************************************

The ConflictDetection property of DataSource set to OverrideChanges. The problem will be solved. :D

gridview sql timeout

I have a simple gridview displaying data from an MSSQL server 2005. Every now and then I get a sql timeout error. Listed below. Can anyone explain why I am getting this error? The connection pool is 100 and the timeout is set to 360. I have checked to current connections in SQL and they never max over 23. There are not locks in SQL when the problem occurs. The query is a stored procedure in sql and when sent sample data it normally takes about 5 seconds.

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 12/3/2007 9:46:37 PM
Event time (UTC): 12/4/2007 3:46:37 AM
Event ID: 140501f9a7744dfea2e445ed00939e44
Event sequence: 42
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/ROOT-1-128412128787656250
Trust level: Full
Application Virtual Path: /
Application Path: c:\inetpub\wwwroot\
Machine name: DD-MAIN

Process information:
Process ID: 5544
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:
Exception type: SqlException
Exception message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Request information:
Request URL:http://localhost/Search_DG.aspx?SearchWord=1212
Request path: /Search_DG.aspx
User host address: 10.10.10.1
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:
Thread ID: 1
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.WebControls.GridView.get_Rows()
at Install_DG.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Custom event details:

For more information, see Help and Support Center athttp://go.microsoft.com/fwlink/events.asp.

Hi

I think you need to set the timeout property of Data objects, other than Connection object.

Please refer the URL :http://techielion.blogspot.com/2007/01/error-timeout-expired-timeout-period.html|||

I think this is what you were referring to.

http://www.velocityreviews.com/forums/showpost.php?s=4fa167ceba48b31fab486f5381b1455d&p=436028&postcount=4

I will try this and let you know if it worked. It will take a good day to test.

Thanks for the info.

|||

Thanks for the help. I have tested the timeout setting on the selecting event for the gridview and it worked great.

Gridview Sorting

I have a gridview that has AllowSorting="true" however I need to implement my own sorting because I have DateTime and Integer data types in several of the columns and I don't want an int column sorted like 1,12,2,23,3,34,4,45,5,56, etc. So, I've added SortParameterName="sortBy" and adjusted my stored procedure to accept this. For only ASC sorting, I've got

ORDER BY
CASE WHEN @.sortBy='' THEN DateCreated END,
CASE WHEN @.sortBy='DateCreated' THEN DateCreated END

and so on. However, columns can also be sorted with DESC. I tried CASE WHEN @.sortBy='DateCreated DESC' THEN DateCreated DESC END, but I get a syntax error on DESC. How can I do this?

If your select is actually returning a datatype of int, it should sort normally. If it's returning an int in a varchar, then well...|||

That's not what I was going for. I am using Atlas to do live searching/filtering of the gridview, and in order to use LIKE in my WHERE clause, I had to convert all datatypes to string. I've solved the problem by using

DECLARE @.sort AS varchar(63)
IF (RIGHT(@.sortBy,4)='DESC') BEGIN
SET @.sort=LEFT(@.sortBy,LEN(@.sortBy)-5)
END
ELSE BEGIN
SET @.sort=@.sortBy
END

with what I had before. Then in my code-behind, if "DESC" is part of the param, I start at the bottom of the table and insert rows into a new table.

If

sortBy.EndsWith("DESC")ThenDim dt2As DataTable = dt.CloneFor iAsInteger = dt.Rows.Count - 1To 0Step -1Dim rAs DataRow = dt.Rows(i)

dt2.ImportRow(r)

Next

dt = dt2

EndIf

Gridview Search

I tried doing a text box search within Gridview. My code are as follows. However, when I clicked on the search button, nothing shown.

Any help would be appreciated. I'm using an ODBC connection to MySql database. Could it be due to the parameters not accepted in MySql?

Protected

Sub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectCommand =

"SELECT * FROM carrier_list WHERE carrierName LIKE '%' + @.carrierName + '%'"

EndSub

Sub doSearch(ByVal SourceAsObject,ByVal EAs EventArgs)

GridViewCarrierList.DataSourceID ="SqlDataSource1"

GridViewCarrierList.DataBind()

EndSub

HTML CODES (Snippet)<asp:ButtonID="btnSearchCarrier"runat="server"onclick="doSearch"Text="Search"/>

' Gridview
<asp:GridViewID="GridViewCarrierList"runat="server"DataSourceID="SqlDataSource1">

</asp:GridView>

<

asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"SelectCommand="SELECT * FROM carrier_list"></asp:SqlDataSource>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"><SelectParameters><asp:ControlParameterControlID="txtSearchCarrier"Name="carrierName"PropertyName="Text"Type="String"></asp:ControlParameter></SelectParameters>

</asp:SqlDataSource>

It's a syntax error on your SQL statement.

Try this:

SqlDataSource1.SelectCommand = "SELECT *FROM carrier_listWHERE carrierNameLIKE'%" + @.carrierName + "%'"
You had an extra ' after first '% and before last %'
Hope this helps and let me know if it worked.
Jae.
|||

It reverted with a :

"Character is not valid." error.

Line 33: SqlDataSource1.SelectCommand = "SELECT * FROM carrier_list WHERE carrierName LIKE '%" + @.carrierName + "%'"

|||

check what your server is passing to sqldatasource by doing following:

response.write("SELECT * FROM carrier_list WHERE carrierName LIKE '%" + @.carrierName + "%'")

it print out:

SELECT * FROM carrier_list WHERE carrierName LIKE %yourvalue%

Also, note that your value (carrierName) should not contain any single quote or double quote.

Hope this helps.

Jae.

|||

check what your server is passing to sqldatasource by doing following:

response.write("SELECT * FROM carrier_list WHERE carrierName LIKE '%" + @.carrierName + "%'")

it print out:

SELECT * FROM carrier_list WHERE carrierName LIKE '%yourvalue%'

Also, note that your value (carrierName) should not contain any single quote or double quote.

Hope this helps.

Jae.

|||

Hi it still prompts the same error:

response.write(

"SELECT * FROM carrier_list WHERE carrierName'%" + @.carrierName + "%'")|||

i just looked at your code from beginning again.

1. it's VB, so why should you use +? instead of &? (sorry i thought of C#)
2. you're mising LIKE on above statement.
3. you can't LITERALLY pass @.carrierName as value. Your value is txtSearchCarrier.text
4. I don't understand why you have 2 sqldatasource (Delete sqldatasource2 - this will show same effect, read on)

So, let's write it again and clean up a bit:

SqlDataSource.SelectCommand = "select * from carrier_list where carriername like '%" & txtSearchCarrier.text & "%'"

Also, you don't need <controlparameter> tag within "select parameter", try this approach:

HTML CODES (Snippet)

<asp:Textbox id="txtSearchCarrier" runat="server"/>
<asp:Button ID="btnSearchCarrier" runat="server" onclick="doSearch" Text="Search" />

' Gridview
<asp:GridView ID="GridViewCarrierList" runat="server" DataSourceID="SqlDataSource1" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" />

That's it.

This will show ALL carriers like you had with sqldatasource2, but with only one sqldatasource1 (because it will pass like '%%' whichi will return all)
*** Also, when carrier name is typed into txtSearchCarrier (obviously a textbox), it will return result sets with characters displayed in textbox.
*** Also, you should have your LOAD_PAGE empty.

If you don't want to diplay anything at first, don't bind DataSourceID = "sqldatasource1", but rather do it on btnSearchCarrier_OnClick handler.
Something like this:

sub btnSeachCarrier_OnClick (....)
.... you other code ...
gridViewCarrierList.datasourceid = "sqlDataSouce1"
gridViewCarrierList.databind()
end sub

This way, you only retrieve data when you click "searchcarrier" button.

Hope this helps and if it doesn't send me the aspx page and I will help you with it. (send it to my email,jae.lee@.jaeleeandco.com)

Jae.

|||

just in case, you HAVE to do following:

1. delete PAGE_LOAD

2. add select command to on_click look at below:

sub btnSeachCarrier_OnClick (....)
.... you other code ...
SqlDataSource.SelectCommand = "select * from carrier_list where carriername like '%" & txtSearchCarrier.text & "%'"
gridViewCarrierList.datasourceid = "sqlDataSouce1"
gridViewCarrierList.databind()
end sub

|||

Thanks Jae,

Actually I used

SqlDataSource1.SelectCommand ="SELECT * FROM carrier_list WHERE carrierName LIKE ? '%' ORDER BY carrierName ASC"

instead and it works.

Will try your suggestion too! Thanks!

Gridview refresh after update

Hi All,

I am new to development of asp. I have an SQLDataSource set as the data source for a grid view. When I click on the edit link in the Gridview, change the data, and click update, the old data is still displayed in the row.

I found exact same issue as here --http://forums.asp.net/thread/1217014.aspx

Solution in the above thread is to add this

{
if (reader != null) reader.Close();
}
conn.Close();

How do I apply above solution in my situation ?

I am updating through stored procedure.and don't have code at background. My code is

Datasource :

<

asp:SqlDataSourceID="ds"runat="server"ConnectionString="<%$ ConnectionStrings:ds %>"

CancelSelectOnNullParameter="False"ProviderName="<%$ ConnectionStrings:ds.ProviderName%>"UpdateCommand="usp_save"UpdateCommandType="StoredProcedure"EnableCaching="False">

<UpdateParameters>

<asp:ParameterName="field1"Type="String"/><asp:ParameterName="field2"Type="String"/><asp:ParameterName="field3"Type="String"/><asp:ParameterName="field4"Type="String"/><asp:ControlParameterName="field5"Type="String"ControlID="label7"/></UpdateParameters>

Anyone Please ?? Help me with this . I am still not able to find the solution.

Thanks in advacne

|||Where is your select statement?|||

Thanks for the reply .

I do select also using stored procedure. I can post stored procedure code if needed.

Here is the full sqldatasource and function

<asp:SqlDataSource
ID="idpl"
runat="server"
ConnectionString="<%$ ConnectionStrings:idpl %>"
SelectCommand="sp_Mapping"
SelectCommandType="StoredProcedure"
CancelSelectOnNullParameter="False"
ProviderName="<%$ ConnectionStrings:idpl.ProviderName%>"
UpdateCommand="sp_SaveMapping"
UpdateCommandType="StoredProcedure"
OnUpdating="pnl_Updating" EnableCaching="False">
<SelectParameters>
<asp:ControlParameter ControlID="Txt1" Name="OriginalID" Type="String" PropertyName="Text" DefaultValue="" />
<asp:ControlParameter ControlID="Txt2" Name="Name" Type="String" PropertyName="Text" DefaultValue="" />
<asp:ControlParameter ControlID="DDL" Name="sName" Type="String" DefaultValue="None" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="OriginalID" Type="String" />
<asp:Parameter Name="sName" Type="String" />
<asp:Parameter Name="PartNum" Type="String" />
<asp:Parameter Name="plantName" Type="String"/>
<asp:ControlParameter Name="userID" Type="String" ControlID = "label7" />
</UpdateParameters>
</asp:SqlDataSource>

protected void pnl_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
DbParameterCollection CmdParams = e.Command.Parameters;
ParameterCollection UpdParams = ((SqlDataSourceView)sender).UpdateParameters;

Hashtable ht = new Hashtable();
foreach (Parameter UpdParam in UpdParams)
ht.Add(UpdParam.Name, true);

for (int i = 0; i < CmdParams.Count; i++)
{
if (!ht.Contains(CmdParams[i].ParameterName.Substring(1)))
CmdParams.Remove(CmdParams[i--]);
}

}

|||

Does the database values change?

If no, then the update isn't happening correctly, use the sql profiler to see what is being generated, and why it is failing to update correctly.

If yes, then in the sqldatasource's Updated event, add a gridview.databind and see if that resolves your problem. If it does not, place a breakpoint in the sqldatasource's Selecting event, and make sure that it is getting called after an update.

|||

Yes .. Database value changes.So stored procedure is definitely working.

I'll try to follow your suggestions on updated event and update the post soon.

Thanks for your help.

|||

Hi Motley,

I followed your suggestion.

1. Added gridview.databind at "updated" event.

2. Applied the breakpoint and made sure that the even is getting fired.

Still having the same issue. Gridview still shows two rows. Old and newly updated.

Any more pointers will be greatly appreciated.

Thanks

|||

Not sure if your problem is fixed or not. Sounds like your update statement has truncated to an insert statement. Have you looked into make sure it is pulling the PK of the table that singularly references the field you are looking for?

Gridview question

Sqldatasources are used for a dropdownlist and a gridview. How can the dropdownlist selection refresh the gridview? This is done programmatically in ASP.NET 1.1 code behind. Can it be done in ASP.NET 2.0 without code behind? Thanks.

Hi,

the SqlDataSource controls hasfilterparameters that you can set through the wizard, or in markup, and then you can use for example the controlparameter:

<asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>

Be sure totake a look at this example.

Grz, Kris.

|||

Thanks. But how can the following be implemented in the FilterParmeters?

Sub LoadGrid()
Dim sqlText As String
If IsPostBack And cboState.SelectedValue <> "0" Then
sqlText = "SELECT * FROM Customers WHERE State='" & cboState.SelectedValue & "'"
Else
sqlText = "SELECT * FROM Customers"
End If
gridCust.DataSource = GetDataView(sqlText, cnn)
gridCustDataBind()
End Sub

Gridview in asp.net

Can I directly Save data to sqlserver 2005 using gridview in frontend?

How?

Hi,

Yes it is possible if you use DataSource control provided in Visual Studio 2005. You don't have to write a single line of code for adding, deleting, updating. All you need it to configure datasource select tables and make queries through the wizard.

Hope it will work

Thanks and best regards,

|||

You can't directly insert data to sqlserver 2005 using gridview.

DetailsView can suit your need.

Here is am example:http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx

GridView Help

Hi,

I use WVD and SQL Express 2005.

I have a table "SignIn" that one of fields inserted automatically by getdate()

And I have GridView that I use to display this table because I would like take advantage of GridView sorting and paging methods that are embedded in.

Currently I display all records at once.

My problem is how to make the GridView show today's records only.

I tried this code below, but I get only this message "There are no data records to display."

<asp:SqlDataSourceID="SqlDataSource1"runat="server"

ConnectionString="<%$ ConnectionStrings:RC1%>"

ProviderName="<%$ ConnectionStrings:RC1.ProviderName%>"

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

<SelectParameters>

<asp:QueryStringParameterName="SignIn"QueryStringField="Format(Now, "M/dd/yyyy")" Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

Help Please!

I don't think you need use QueryStringParameter here. You can add the selectparameter from page load to assign today's date to it:

Like:

protectedvoid Page_Load(object sender,EventArgs e)

{

SqlDataSource1.SelectParameters.Add(

"SignIn",DateTime.Today.ToString("MM/dd/yyyy"));

}

}

The following is for a QueryStringParameter, but you don't need it.

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

<SelectParameters>

<%

-- <asp:QueryStringParameter DefaultValue="01/01/2007" Name="SignIn" QueryStringField="mydate" Type="DateTime" />

--

%><asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

Your URL will look something like this:

http://localhost:2013/WebSite1/queryDate.aspx?mydate=1/2/2006

|||

Thank you Limno,

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

This SelectCommand solved my problem.Cool

I tried the

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

And I inserted SelectParameters like this:

<asp:SqlDataSourceID="SqlDataSource1" . . .

.

.

.

<SelectParameters>

<asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

I keep getting the following error:

The variable name '@.SignIn' has already been declared. Variable names must be unique within a query batch or stored procedure

I wonder what I did wrong?

Thank you.

|||

alexmu06:

Thank you Limno,

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

This SelectCommand solved my problem.Cool

I tried the

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

And I inserted SelectParameters like this:

<asp:SqlDataSourceID="SqlDataSource1" . . .

.

.

.

<SelectParameters>

<asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

I keep getting the following error:

The variable name '@.SignIn' has already been declared. Variable names must be unique within a query batch or stored procedure

I wonder what I did wrong?

Thank you.

When you add the selectparameter from your code, you cannot use the declaratively again. You can use only one of them. I would prefer teh code one in your case and I hope this answers your question.

|||

Sorry but i don't get it.

if its possible could you expand a bit.

Thanks

|||

Hello:

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

and the following is all you need.

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

Please do not add that QueryStringParameter in your SelectParameters for this "SignIn"(you've already had it from the above code).

|||

Thank you,

I'll try that

Alex

gridview edit/delete

In gridview the edit and delete links appear where they belong and on edit the proper expanded edit bar appears allowing me to make changes, but when I click update it closes the edit bar and returns me to my original position without posting the changes.

The same thing happens when I attempt to delete a record.

The database is a single table and I assume the connection string is OK as evidenced by the fact the data is displayed correctly. Edit and delete were selected from the drop-down options menu on the gridview as opposed the inside the properties box.

To really drive me off the deep end, if I create a new site and data base following all the same procedures, I have a 50/50 chance that it will work properly, and I promise I haven't been drinking...yet.

Can anyone shed any light on what's happening here? It feels like I'm missing a step somewhere, but can't figure out where.

Many thanks!

What application are you using to edit your data? What are you doing to view your data in a grid?

In SQL Server 2005 Management Studio, you can right click on the table in Object Explorer and then select "Open Table" in the context menu to bring up an editable grid. You should be able to modify your data directly in the grid.

Hope this helps,
Steve

|||You might need to check the privileges for the account using this way, as it is better to edit or delete the table rows using Queyr editior with TSQL statements.|||

Hi,

I am facing a problem with a Editable grid view.

We have overridden the create row method in gridview to make it multi row editble by setting the rowstate property to edit on the selected row indexes.

We are having dropdowns in edit mode. Till it goes to edit mode it works fine but the after that when click on any button .it displays the "Failed to load view state Error" The controls used to load view state does not match.....

this error only happenes when we use a drop down and dynamically add the dropdown values when on row_created event of datagrid.

Any help would be appriciated.

Regards,

Alok

gridview edit/delete

In gridview the edit and delete links appear where they belong and on edit the proper expanded edit bar appears allowing me to make changes, but when I click update it closes the edit bar and returns me to my original position without posting the changes.

The same thing happens when I attempt to delete a record.

The database is a single table and I assume the connection string is OK as evidenced by the fact the data is displayed correctly. Edit and delete were selected from the drop-down options menu on the gridview as opposed the inside the properties box.

To really drive me off the deep end, if I create a new site and data base following all the same procedures, I have a 50/50 chance that it will work properly, and I promise I haven't been drinking...yet.

Can anyone shed any light on what's happening here? It feels like I'm missing a step somewhere, but can't figure out where.

Many thanks!

What application are you using to edit your data? What are you doing to view your data in a grid?

In SQL Server 2005 Management Studio, you can right click on the table in Object Explorer and then select "Open Table" in the context menu to bring up an editable grid. You should be able to modify your data directly in the grid.

Hope this helps,
Steve

|||You might need to check the privileges for the account using this way, as it is better to edit or delete the table rows using Queyr editior with TSQL statements.|||

Hi,

I am facing a problem with a Editable grid view.

We have overridden the create row method in gridview to make it multi row editble by setting the rowstate property to edit on the selected row indexes.

We are having dropdowns in edit mode. Till it goes to edit mode it works fine but the after that when click on any button .it displays the "Failed to load view state Error" The controls used to load view state does not match.....

this error only happenes when we use a drop down and dynamically add the dropdown values when on row_created event of datagrid.

Any help would be appriciated.

Regards,

Alok

GridView delete function

This is killing me. I've searched the forums for hours and can't find the answer. My SQLDataSource is working fine except when I want to delete. I've allowed the delete function to be shown on the gridview. This is my SQLDataSource:

 <asp:SqlDataSource ID="IndexDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:IndexConnectionString%>" SelectCommand="SELECT * FROM [Index] WHERE (Type LIKE '%' + @.SearchText2 + '%') OR (Product LIKE '%' + @.SearchText2 + '%') OR (Version LIKE '%' + @.SearchText2 + '%') OR (Binder LIKE '%' + @.SearchText2 + '%') OR (Language LIKE '%' + @.SearchText2 + '%') OR (CDName LIKE '%' + @.SearchText2 + '%') OR (Details LIKE '%' + @.SearchText2 + '%') OR (ISOLink LIKE '%' + @.SearchText2 + '%')" DeleteCommand="DELETE FROM [Index] WHERE [ID] = @.original_ID" UpdateCommand="UPDATE [Index] SET Type = @.Type, Product = @.Product , Version = @.Version, Binder = @.Binder, Language = @.Language, CDName = @.CDName, Details = @.Details, ISOLink = @.ISOLink WHERE ID = @.ID"> <SelectParameters> <asp:ControlParameter Name="SearchText2" Type="String" ControlID="SearchText2" PropertyName="Text" ConvertEmptyStringToNull="False" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="original_ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Type" /> <asp:Parameter Name="Product" /> <asp:Parameter Name="Version" /> <asp:Parameter Name="Binder" /> <asp:Parameter Name="Language" /> <asp:Parameter Name="CDName" /> <asp:Parameter Name="Details" /> <asp:Parameter Name="ISOLink" /> </UpdateParameters> </asp:SqlDataSource>


It doesn't give me an error if I click delete but it doesn't delete the record. I've tried changing the DeleteParameter to <asp:Parameter Name="ID" Type="Int32" /> but it gives me the error "Must declare the scaler variable of '@.ID'"... I saw in this post http://forums.asp.net/p/1077738/1587043.aspx#1587043 that the answer was that "The variable you have declared in the definition of the proc isdifferent from the variable you are using in the WHERE clause." when they are both the same. Thanks for any help.

-Brandan

Hello

What if you add a semicolumn after @.original_ID ? like this"DELETE FROM [Index] WHERE [ID] = @.original_ID;"

|||

Is the ID column your table's primary key? If yes, you need to make sure that the ID is set in your GridView's DadaKeyNames and you should change your DeleteParameter to <asp:Parameter Name="ID" Type="Int32" /> and DeleteCommand="DELETE FROM [Index] WHERE [ID] = @.ID"

If you cannot make this work, please post your GridView part here and if you can list all your columns' name instead of a * in your SELECT statement, that would be great. Thanks.

|||

If it doesn't fixes it it might just be the DataKeyNames field of the gridview that need to be set to ID .

|||

**RESOLVED**

It was definitely the DataKeyNames. I had recreated the gridview so many times I forgot to put it back in. thanks ya'll.

Gridview delete behavior change from beta2 in VWD express

I've not been able to test this yet in full VS2005 (MS is screwed up with orders for some reason. Has anyone heard this one. All orders for less than quantity=5 were being rejected). So, instead of waiting for it I installed VWD Express. Now, the project had been built in VWD express beta 2, so no big change there.
Several gridview controls in the project had <Delete> enabled. Just <Delete> mind you. Nothing else for command buttons. They all worked fine with delete queries that use gridview.selectedvalue as the parameter. Every single one stopped working since I've converted from beta 2 to RTM!
Here's what I determined. The delete will only work if the row in the grid is selected first!. Otherwise <selectedvalue> is null when you click on <Delete>.
Is this a bug or what?
I'd be happy to supply more details. I am certain others will report this, but I have yet to find a post here or in any blogs out there that reproduce this problem in the RTM of .NET 2.0

On looking more closely at my earlier implementation of <Delete> I realize that the ParameterSource for the key in the grid is actually set to None in dotnet 2.0 beta 2. And it works fine. It seems to just automatically pick up the grid <datakey> value, even when that is a composite key.
My struggles to make <Delete> work again took me down the road of modifying the parameter values which is how I came to my earlier conclusion. Suffice it to say, that <Delete> in the gridview worked very automatically in beta 2. And now, no matter how much I try, the <Delete> function does not work at all.
I will keep playing with it, to see if there is some workaround other than coding things all over again to do deletes in a much more manual way.
Also, I've definitively reproduced my results by moving a working page back and forth from a .NET 2.0 beta 2 and .NET 2.0 RTM environment. Both in a development machine and W2003 server environments. As soon as I take the working page with <Delete> in the gridview from beta 2 to rtm, the <Delete> feature fails.
Anybody else that has a chance to check this out please let me know if you can reproduce this problem.

|||Hate to admit it, but I overlooked an old post here that gave me the hint I needed. Anyway, looking at delete query with SQLprofiler made it very clear. Removing the parameter for the <Delete> and changing the delete query to use the grids datakey field corrected things. Still, I have to compare this asp file to my old beta 2 file and see what happened when I copied it over and used it on the .NET 2 RTM development system. I am sure the behavior changed when I transitioned the project to the rtm version. Hope this saves others some head scatching...

gridview binding with sqlConnection objects...

Hello All, I am new to data access and

i have got the problem to display the data into the page by binding the gridview with sqlConnection, sqlCommand and sqlDataReader objects. The actually code is written as:

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!Page.IsPostBack)

{

SqlConnection myConnection;

SqlCommand myCommand;

SqlDataReader myReader;

myConnection =newSqlConnection();

myConnection.ConnectionString =ConfigurationManager.ConnectionStrings["LatteConnectionString"].ConnectionString;

myCommand =newSqlCommand();

myCommand.CommandText ="select * from AntiVirusVendors";myCommand.CommandType =CommandType.Text;

myCommand.Connection = myConnection;

myCommand.Connection.Open();

myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

GridView1.DataSource = myReader;

GridView1.DataBind();

myCommand.Dispose();

myConnection.Dispose();

}

}

and the GridView in html is listed as:

<div>

<asp:GridViewID="GridView1"runat="server">

</asp:GridView>

</div>

So the problem is --> there is nothing shown in the page, no errors no anything... just the empty page.

Any ideas would be appreciated. Thanks in advance!

Joe

sorry, the problem has been solved.

GridView based on SQLServerDataSource using a Select Union statement, impacts on Update an

I have a GridView dispalying from a SQLServerDataSource that is using a SQL Select Union statement (like the following):

SELECT
FirstName,
LastName
FROM
Master
UNION ALL
SELECT
FirstName,
LastName
FROM
Custom
ORDER BY
LastName,
FirstName

I am wondering how to create Update and Insert statements for this SQLServerDataSource since the select is actually driving from two different tables (Master and Custom). Any ideas if or how this can be done? Specifically, I want the Custom table to be editable, but not the Master table. Any examples or ideas would be very much appreciated!

Thanks,

Randy

SELECT
FirstName,
LastName,0 AS Editable
FROM
Master
UNION ALL
SELECT
FirstName,
LastName,1 AS Editable
FROM
Custom
ORDER BY
LastName,
FirstName

Only allow rows that editable is 1 to be edited, then use an update statement directly on custom for the rows that get editted.

|||

Thank you for the direction. I am unclear on your last sentence...can you provide a code snippet that illustrates what you are explaning?

I appreciate the help

Randy

|||

UPDATE Custom SETFirstName=@.FirstName,LastName=@.LastName WHEREFirstname=@.original_FirstName ANDLastName=@.original_LastName

|||

Thanks, the Update statement makes sense.

Last question: when you say "Only allow rows that editable is 1 to be edited", can you provide direction on what the code would be such that the EditTemplate never appears for Editable = 0? (i.e. so that Rows where Editable = 1 can go into edit mode but rows where Editable = 0 cannot).

Sorry for what may be basic questions...

|||

I really can't without knowing more about what it is you are trying to do, or how you've implemented your edit functionality.