HTLM encodeformatstring of selected field of edit field of gridview ? datetime ? datetime.now () and insert code lines

hi friends

i changed HTLM encodeformatstring of selected field of edit field of gridview as false.. i also changed HTLM encode as false..i entered dataformatstring as {0:DD/MM/YYYY}

then i tried below code line for inserting record.. datatype of table1 is datatime.. thic code lines run good before i changed HTLM encodeformatstring and HTLM encode and dataformatstring.. but this code lines doesnt run now. inserting of my backup web sites doesnt work.. i think that datetimeformat of my computer changed.. How can i fix it ? What can problem be ? Cheers

sds.ConnectionString = ConfigurationManager.ConnectionStrings("CS").ToString

sds.InsertCommandType = SqlDataSourceCommandType.Text

sds.InsertCommand = "INSERT INTO urunlistesi (timeone) VALUES (@timeone)"

sds.InsertParameters.Add("timeone", datetime.now())

Dim rowsaffected As Integer = 0

Try

rowsaffected = sds.Insert()

Catch ex As Exception Server.Transfer("help.aspx")

Finally

sds = Nothing

End Try

If rowsaffected <> 1 Then

Server.Transfer("help.aspx")

Else

Server.Transfer("ok.aspx")

End If

 

when i change 14.06.2008 to 10.06.2008 from my computer, inserting run for datetime.now()

but when i change 10.06.2008 to 14.06.2008 from my computer.. inserting doesnt run for datetime.now()

Also when i enter {0:dd/MM/YYYY hh:mm:ss} to formatstring of edit column of gridview, gridview display 33.06.2008 18:28:54..for 14.06.2008 what is problem ? (HTLM encode = false )

how can i fix it ?


Mark as me if my question or my answer can be helpful for you :)
0
oguzkaygun
6/14/2008 9:06:40 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
914 Views

Similar Articles

[PageSpeed] 7

Hi oguzkaygun ,

See my sample, works perfectly.

 

    protected void Button1_Click(object sender, EventArgs e)
    {
        
        this.SqlDataSource1.InsertParameters["mytime"].DefaultValue = DateTime.Now.ToString();
        this.SqlDataSource1.InsertParameters["id"].DefaultValue = "3";
        this.SqlDataSource1.Insert();


    }
  
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            DeleteCommand="DELETE FROM [timetest] WHERE [id] = @id" InsertCommand="INSERT INTO [timetest] ([id], [mytime]) VALUES (@id, @mytime)"
            SelectCommand="SELECT * FROM [timetest]" UpdateCommand="UPDATE [timetest] SET [mytime] = @mytime WHERE [id] = @id">
            <DeleteParameters>
                <asp:Parameter Name="id" Type="Int64" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="mytime" Type="DateTime" />
                <asp:Parameter Name="id" Type="Int64" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="id" Type="Int64" />
                <asp:Parameter Name="mytime" Type="DateTime" />
            </InsertParameters>
        </asp:SqlDataSource>
    
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
                <asp:BoundField HtmlEncode="false" DataField="mytime" DataFormatString="{0:dd-MM-yyyy}" HeaderText="mytime"
                    SortExpression="mytime" />
            </Columns>
        </asp:GridView>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="insert" />
    </form>

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
6/17/2008 3:28:48 AM

hi

thank you for your reply :) it doesnt run for me.. defaultvalue has underline and this has underline

my datetime format is 17.06.2008

i should change 17.06.2008 to 06.17.2008 for datetime.now() before inserting..

how can i do this ?

i tried below codes.. my resut is 16/02/1992 12:15:12 but this sample say that resut is '2) myDateTimeFrench = 2/16/1992 12:15:12 PM

Dim myDateTimeValue As String = "2/16/1992 12:15:12"
      Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue)
      Console.WriteLine("1) myDateTime       = {0}", myDateTime)
     
      ' Reverse month and day to conform to a different culture.
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim culture = New CultureInfo("fr-FR", True)
      Dim myDateTimeFrenchValue As String = "    16/02/1992 12:15:12"
      Dim myDateTimeFrench As DateTime = _
                           DateTime.Parse(myDateTimeFrenchValue, _
                                          culture, _
                                          DateTimeStyles.NoCurrentDateDefault)
      Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench)
     
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim expectedFormats As String() =  {"G", "g", "f", "F"}
      myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, _
                                          expectedFormats, _
                                          culture, _
                                          DateTimeStyles.AllowWhiteSpaces)
      Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench)
   End Sub 'Main
End Class 'Class1
'
'This example yields the following results:
'
'1) myDateTime       = 2/16/1992 12:15:12 PM
'2) myDateTimeFrench = 2/16/1992 12:15:12 PM
'3) myDateTimeFrench = 2/16/1992 12:15:12 PM
'

cheers


Mark as me if my question or my answer can be helpful for you :)
0
oguzkaygun
6/17/2008 9:43:41 AM

hi

i have solved this problem with below code

TextBox1.Text = DateTime.Now()

TextBox2.Text = TextBox1.Text.Substring(5)

TextBox3.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 17)

TextBox4.Text = TextBox1.Text.Substring(3, TextBox1.Text.Length - 16)

TextBox5.Text = TextBox4.Text + TextBox3.Text + TextBox2.Text

insert textbox5.text :)

cheers


Mark as me if my question or my answer can be helpful for you :)
0
oguzkaygun
6/17/2008 5:22:25 PM
Reply:

Similar Artilces:

How to define a global datetime format to display datetime field in Gridview control?
How to define a global datetime format to display datetime field in Gridview control?                       The CreateDate is a datetime field, it display default datetime format such as 1995-12-26 11:20:12 in Part A I hope it display a appointed format, so I set DataFormatString in Part B If I have many datetime fields in different GridView control, do I must set DataFormatString one by one? Thanks! //------------------------------------------Part A----------------------------...

datetime.now() and datetime.now().addmonths()..insert code run before.. but it doesnt run now... i have no done anything.. why dont it run itself ?
hi datetime.now() and datetime.now().addmonths().. it run before.. but it doesnt run now... i have no done anything.. why doesnt it run now ? my datatype is datetime.. what can problem be ? sds.InsertParameters.Add("ilanbaslangictarihi", DateTime.Now()) hello friends when i change 14.06.2008 to 10.06.2008 from my computer, inserting run for datetime.now() but when i change 10.06.2008 to 14.06.2008 from my computer.. inserting doesnt run for datetime.now() Also when i enter {0:dd/MM/YYYY hh:mm:ss} to formatstring of edit column of gridview, gridview display 33.06.2008 1...

Only select few fields to gridview when clicking some fields on gridview remaining fields should be in a popup window
Pls help me out this. I am having a table of 30 fields.. i dont want to show everyfields in the gridview that would be very messy. i need to show only 2 or 3 fields in the gridview and if the user click on any of the field in the gridview the 30 fields should be shown in a small size window....  And the small size window should have a button(e.g: approved) to update a field(approved field : no to yes) in the table...... Is there any possibilities to do this..if so pls guide me... Thanks in advance Hi muthulakshmanan , Add some boundfield to GV, which used to show only few co...

Problem inserting Now() into a datetime field
HiI am trying to insert value retrieved from Now() into a datetime field in my MSDE database, but I am getting the following error, and I have no idea what is going wrong.Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.Here is the code I am using:Dim user As String = MyContext.User.Identity.Name.ToString Dim TimeDate As DateTime = Now() Dim status As String = "Pending" With SqlOrders.InsertParameters .Item("UserName").DefaultValue = user .Item("OrderDate").DefaultValue = Tim...

How to use GridView with DateTime field as selection
Hi,I have created a GridView that display a SQLEXPRESS table. The problem is that I cannot get it to display any data after I added via the Configure Data Source the WHERE clause. Please see it in bold:  SelectCommand="SELECT [InvoiceNo], [InvoiceDate], [CustomerID], [Total] FROM [InvoiceHdr] WHERE (([InvoiceDate] >= @InvoiceDate) AND ([InvoiceDate] <= @InvoiceDate2))">The 2 dates are passed in as query string this way: http://localhost:1786/MyTimesheet/Report/InvoiceList.aspx?InvDateFr=1/09/2006&InvDateTo=30/09/2006The table defined is -->&...

This code is not finding any DateTime fields, but they are there... [Edit]
The SQLServer table in question has two columns of data type DateTime. Yet the following code finds none: {code} procedure TUTUForm.cmbxDateColumnsDropDown(Sender: TObject); var i: Integer; begin cmbxDateColumns.Clear; // Popul8 with DateTime columns from table for i := 0 to Pred(ADOTable.FieldCount) do if ADOTable.Fields[i].DataType = ftDateTime then cmbxDateColumns.Items.Add(ADOTable.Fields[i].Name); end; {code} Why [not]? Edited by: Clay Shannon on Sep 20, 2011 1:36 PM Okay, when I prepended this: {code} if not ADOTable.Active then ADOTabl...

Inserting DateTime.Now into a field in DetailsView
Hi guys,I'm developing an ASP.NET website and my database is being stored on SQL server 2005. One one of my .aspx forms I have a 'DetailsView' for inserting data into the database.   What I want to know is how do you automatically insert the system's time into the database without actually typing anything in the 'date' field?  Please help me! Thanks!  Hi, The easy way I think is to use a default value for this column in your table. Assign a default value for your datetime field with getdate() and The column will get a date and time when a reco...

Calendar Control - SQL datetime field
Hi, I have a webform where the staff can request a day off, everything is working perfectly except from the fact that it refuses to save the date into the date field properly, opting to save dates along the lines of '05/15/1900 00:00:00' which as you can imagine is not much use to me. The field in the SQL table is set to 'datetime' and the ASP.NET code used to insert the record into the database is as follows; DBInsert.CommandText = "Insert INTO TBL_Holidays " _ & "(AgentRef, WhenRequested, ActivityDate, TimeTaken, TheNote, Status, TeamRef) Values ...

Very simple question regarding a DATETIME field; select fields matching month/day/year
Hello All,I've got a DATETIME field, and it includes hour:minutes:second data.  I want to do selects where I can simply match on the month, day and year.  For instance, something like this:SELECT * FROM QuizAttempts WHERE DateTimeTaken = '1/12/2006'And have it match anything that was taken that day, regardless of *when* it was taken.  Any suggestions?Thanks!  -Josh -jb I wound up doing this:SELECT * FROM QuizAttempts WHERE (CONVERT(varchar(10), DateTimeTaken, 101) = '10/5/2005'Substituting in the appropriate date for what I wanted.Is there a better way? -jb SELECT *...

DateTime.Now, an allowed null field, and my Insert function from my dataset
I have a table adapter for one of my SQL2005 tables, and in two different fields I accept a date time. Now 99% of the times, new rows to this table will be filled out using DateTIme.Now(), as a Time Stamp is what I'm going for.   Here is the line of code in question...cops_current_data_adapter.Insert(ProductOrder, Convert.ToInt16(Session["StationId"].ToString()), PartNumber, DateTime.Now, DateTime.Now, Convert.ToInt16(qty), 0);  The second DateTime.Now is the one that can be null, and it's throwing a formatting error everytime I try and drop it in there...

Problem SELECT with datetime field on PB 10.2 and ADO.NET
I'm using ADO.Net Connection in PB 10.2, when I execute a query on a table which a datatime field contains I have this error "Select error: Failed to get datetime data". This error is also made when I create a datawindow with seme query. My Databse Connection Syntax is the following: SQLCA.DBMS=ADO.Net SQLCA.DBMSName="ADO" SQLCA.LogPass=sa SQLCA.LogId=sa SQLCA.AutoCommit=False SQLCA.DBParm=Namespace='System.Data.OleDb',Database='icam',DataSource='server-08-w2003' ,Provider='SQLOLEDB',TrustedConnection=1,PROVIDERSTRING='...

Insert NULL value into datetime field of Oracle database
 Hi all,I have a form which has a textbox where a date is entered by the user - this field is not compulsory so if it is left blank I want to store it in the table as nothing. However, when I use the code below it enters 01/01/0001 instead of nothing. I have tried various other options Endate.MinValue and EndDate = System.DBNull.Value (this throws an error)Im stumped. Anyone have any ideas as to how I can enter a blank value into a date field in my oracle table? Would prefer to do it before I go near the sql Insert (so in my vb.net code) because thats done using a stored procedure and w...

parsing nvarchar() field to DateTime field
Hello all, I'm sure I'll be able to figure this out eventually, but I figured someone else might have done something like this before and I could save some time by not having to re-invent the wheel. (so-to-speak) I have an existing database containing a JobHistory table that has an nvarchar() field that is used to identify a "period" for a Job History record. (see below for example data contained in this field) The client wishes me to change the single nvarchar() field into two DateTime fields. No problem. However, I don't have any ideas yet how I'm go...

DateTime field split into 2 fields
Hi all, I have a DateTime data column (I use MS-SQL 2000) but in my DW I want to display it into 2 fields (date & time). Then I use the same column 2 times: one column with mask dd/mm/yyyy one column with mask hh:mm The retrieve is OK but when the user changes the date -> time is set to 00:00 when the user changes the time -> date is set to 01/01/1900 How to avoid this ? Thanks. Lilian. Lilian; I hate DBMS that only support the one DateTime data type .. don't you? That is why I love my ASA - now to be renamed SQLAnyWhere again...

Web resources about - HTLM encodeformatstring of selected field of edit field of gridview ? datetime ? datetime.now () and insert code lines - asp.net.presentation-controls

Resources last updated: 12/13/2015 8:27:47 AM