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

Friday, March 23, 2012

Problem in concatinating two paramters to update one column

Using gridview to display the data and sql server 2000

I havea column in the database say departtime of datetime datatype thatcntains the date and time resp(09/19/2007 9:00 PM). I am separating thedate and time parts to display in two different textboxes saytxt1(09/19/2007) contaons date and txt2(9:00 PM) contains time by usingthe convert in sqldatasource. Now i need to update the column in thedatabase and i am using Updatecommand with parameters in aspx lkeupdatecommand = "Update table set departtime = @.departtime" . How cani update my column as datetime by getting the data from 2 texboxes asnow i have 2 textboxes displaying data for single column means if useredit the data in txt1 as(10/19/2007) then on click of update i need topopulate the column daparttime as (10/19/2007 9:00 PM).

Please let me know if you have any questions.

Hello Nick,

What you need is the DateTime.Parse method. See:http://msdn2.microsoft.com/en-us/library/system.datetime.parse(VS.71).aspx

This will create a datetime field of your two text fields.

Jeroen Molenaar.

sql

Wednesday, March 21, 2012

Problem getting Recoreds from Store Proedure Between Dates...

i have a gridView and i want to get the recoreds between specific dates.. so i put two calendars to select the dates...

and they will filter the recoreds..(i seleced dates and it returns non recors and theres recored betwenn those dates and in a SQL View it works )

What can i do? Thanks

Store Proceure Function:

CREATE PROCEDUREsp_FindTnoaGrid@.SearchTnoanvarchar(14),@.beginDateas nvarchar(50),@.endDateas nvarchar(50)AS-- order by dbo.V_tnuot.t_erech desc--if (@.beginDate='%')or (@.endDate='%')SELECT dbo.V_tnuot.kod_lakoha, dbo.V_tnuot.t_erech, dbo.V_tnuot.t_peula, dbo.V_tnuot.scum_peulaassum, dbo.V_tnuot.strHpoalimSugKodTnua, dbo.V_tnuot.DescSugPeula,cast(year(cast(@.beginDateas datetime))as nvarchar)+'-'+cast(month(cast(@.beginDateas datetime))as nvarchar)+'-'+cast(day(cast(@.beginDateas datetime))as nvarchar)as try, dbo.V_tnuot.Hpoalim_HodeshSaharFROM dbo.V_tnuotLEFTOUTER JOIN dbo.tblCategTnuot_KodPeulaON dbo.V_tnuot.strHpoalimSugKodTnua = dbo.tblCategTnuot_KodPeula.idKodTnuaWHERE ( kod_lakoha = @.SearchTnoa)if (@.beginDate<>'%')and (@.endDate<>'%')SELECT dbo.V_tnuot.kod_lakoha, dbo.V_tnuot.t_erech, dbo.V_tnuot.t_peula, dbo.V_tnuot.scum_peulaassum, dbo.V_tnuot.strHpoalimSugKodTnua, dbo.V_tnuot.DescSugPeula, dbo.V_tnuot.Hpoalim_HodeshSaharFROM dbo.V_tnuotLEFTOUTER JOIN dbo.tblCategTnuot_KodPeulaON dbo.V_tnuot.strHpoalimSugKodTnua = dbo.tblCategTnuot_KodPeula.idKodTnuaWHERE ( kod_lakoha = @.SearchTnoa)and (dbo.V_tnuot.t_peulaBETWEENcast(@.beginDateas datetime)andcast(@.endDateas datetime) )GO

What happens if you call the stored procedure directly e.g. from a query window in SQL Server Management Studio, passing in the appropriate parameters? Do you get the results you expect?

Are you tripping up over the classic "time" issue - DateTime fields don't just have a date, they have a time component so "2007-08-21" is not the same as "2007-08-21 14:23:08" etc.

Monday, March 12, 2012

Problem encountered with Filterparameter on SQLDataSource for GridView

Hi,

I have a GridView connected to a sqldatasource control. Everything is working great, updates, paging and filtering with one exception. When the user enters in a name like O'Reilly (with a single quote), the page errors. The error returned is:

Syntax error: Missing operand after 'Reilly' operator.

Here is the definition of the sqldatasource:

<asp:SqlDataSource ID="SqlDataSourcePersons" runat="server"
ConnectionString="<%$ ConnectionStrings:database %>"
SelectCommand="SELECT [Id], [FirstName], [LastName],Email, [PersonTypeId], [WorkerId], [_workerNTId], [Title], [City] FROM [Person]"
FilterExpression="(FirstName like '{0}%') AND (LastName like '{1}%') AND (WorkerId like '{2}%') AND (City like '{3}%')" ProviderName="System.Data.SqlClient">
<FilterParameters>
<asp:ControlParameter ControlID="TextBoxFirstName" Name="FirstName" DefaultValue="%" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBoxLastName" Name="LastName" DefaultValue="%" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBoxWorkerId" Name="WorkerId" DefaultValue="%" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBoxCity" Name="City" DefaultValue="%" PropertyName="Text" Type="String" />
</FilterParameters>
</asp:SqlDataSource>

Any suggestions would be appreciated.

Thank you, Jim

Hey

If a filter expression contains reserved characters, such as a single quotation mark, those characters must be specified using escape characters. For example, the following expression shows how to use an escape character to include an apostrophe in the expression:CompanyName = 'Margie\'s Travel'.

Following link might helpful:

http://www.aspnetresources.com/blog/apostrophe_in_rowfilter.aspx

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskfilteringsortingdatausingdataview.asp