|
digimanus wrote: You can do a Convert(varchar, dateTime field, 105) for instance.
Date formatting should be done in the presentation layer. The .NET Framework provides built-in support for this. See the link in my original reply.
|
|
|
|
|
I think it CAN be done in .NET
Let the poster of this problem decide what he wants to.
things like:
DateTime dateValue = DateTime.Now
String whatTime = String.Format("{0:yyyyMMdd}", dateValue);
can also be done.
|
|
|
|
|
digimanus wrote: Let the poster of this problem decide what he wants to.
This forum is a place for people to discuss solutions to problems. If I want to critisize other people's suggestions, I will do. I certainly don't need your permission.
The basic fact of the matter is that using the T-SQL SUBSTRING is a clumsy way to format dates. If T-SQL must be used, the CONVERT function is better. IMHO, .NET provides a much richer API for data presentation and should be the tool of choice.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
biswa47 wrote:
use substring() in sql.
bofore dispaly data in the grid use substring in db
This isn't the right way to do it. The .NET Framework has support for formatting dates in different ways. See the link I provided in my original reply.
|
|
|
|
|
Hello
I'm having trouble uploading images to my sql express database. I have been searching endlessly to find a solution to my problem but to no-avail, I now turn to the trusted codeproject network for some help in solving the answer. I'm new to asp.net and am currently building an application to upload images into a database. I found the following tutorial()[^] and manipulated it to use a stored procedure. Below is the code in my code behind page:
Protected Sub btn_upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_upload.Click
Dim intLength As Integer
Dim arrContent As Byte()
If File_Upload.PostedFile Is Nothing Then
lbl_status.Text = "Please specify an image to upload"
Exit Sub
Else
Dim Filename As String = File_Upload.PostedFile.FileName
Dim ext As String = Filename.Substring(Filename.LastIndexOf("."))
ext = ext.ToLower
Dim image_type = File_Upload.PostedFile.ContentType
If ext = ".jpg" Then
ElseIf ext = ".bmp" Then
ElseIf ext = ".gif" Then
ElseIf ext = "jpg" Then
ElseIf ext = "bmp" Then
ElseIf ext = "gif" Then
Else
lbl_status.Text = "Only gif, bmp, or jpg format files supported."
Exit Sub
End If
intLength = Convert.ToInt32(File_Upload.PostedFile.InputStream.Length)
ReDim arrContent(intLength)
File_Upload.PostedFile.InputStream.Read(arrContent, 0, intLength)
If Upload_File_Server(txt_Image_Title.Text.Trim, arrContent, intLength, image_type) = True Then
lbl_status.Text = "Image uploaded successfully"
Else
lbl_status.Text = "An Error occurred while uploading please try again"
End If
End If
End Sub
Protected Function Upload_File_Server(ByVal title As String, ByVal Content As Byte(), ByVal Length As Integer, ByVal strType As String) As Boolean
Dim command As New SqlCommand("Upload_Article_Image")
conn.Open()
Try
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@Content", Content)
command.Parameters.AddWithValue("@Title", title)
command.Parameters.AddWithValue("@Type", strType)
command.Parameters.AddWithValue("@Length", Length)
command.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
Finally
conn.Close()
End Try
End Function
The problem I am having is that the information is not being stored in the database and the function throws up the exception. If anyone can help me it would be greatfully appricated.
Regards
McGann
|
|
|
|
|
Telling us what the error is would go a long way to helping us answer this.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the response Christian but I searched through google and found a solution to my problem. Thanks for getting back to me.
|
|
|
|
|
use
ex.toString()
inside catch block before returning false. it will help tracing the problem
Ashish Sehajpal
|
|
|
|
|
Hi all,
I'm building a website for a friend and am at the design stage.
I would like to have a table with a row and 5 columns; an add link placed above the table.
I would like each cell to contain a type of web object (of my design) such as a text box (0,1); a drop down list (0,3) etc.
When the user clicks the add link, a second row with the same objects appear below the first row; whilst the data persists in the first row.
I'm not expecting code, but I would appreciate some help in understanding how I can accomplish this.
Thanks
Humble@!
|
|
|
|
|
If you are using ASP.NET, then look at the GridView control. Your 'add row' would be placed in the footer along with a command button to submit the new data back for processing. There are a number of tutorials on the web describing the technique, just search google for "GridView add new row" or something like that.
Here's one example: http://geekswithblogs.net/casualjim/articles/51360.aspx[^]
|
|
|
|
|
how chagne a series excel chart in asp.net
e.g : Chart Wizard : select Row OR column
|
|
|
|
|
Erhm I have no clue what you're asking... anyone??
|
|
|
|
|
|
Is there something wrong with the links on the that page you provided?
Code Samples
Documentation
Knowledge Base
led mike
|
|
|
|
|
there is nothing wrong on provided link, BUT I need a quick start. You may say a short cut
|
|
|
|
|
wEb GuRu... wrote: BUT I need a quick start. You may say a short cut
Those examples are provided as a short cut. You want a short cut to the short cut? WTF dude?
led mike
|
|
|
|
|
Hi all,
I'm trying to extend GridView control to add a DropDownList with values to change the PageSize in the Pager row. To reuse the control in the future, I'd like to add the values to the DropDownList either in the Properties window at design time or in the code behind. I created a class to keep the values and, following instructions found in several forums, add the requested attributes.
Here is the code:
[DefaultProperty("Text")]
[ParseChildren(true), PersistChildren(false)]
public class MyGrid : GridView
{
protected SizeItemCollection _PageSizeItems;
[Category("Paging")]
[Editor(typeof(CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerDefaultProperty), MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("Items list for the PageSize selector DropDownList")]
public SizeItemCollection PageSizeItems
{
get { return (_PageSizeItems != null ? _PageSizeItems : new SizeItemCollection()); }
}
protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
{
}
}
public class SizeItem : Component
{
private int _size;
public SizeItem() { }
public SizeItem(int size)
{
_size = size;
}
public int Size
{
get { return _size; }
set { _size = value; }
}
}
public class SizeItemCollection : CollectionBase
{
}
I managed to see the PageSizeItems modal form at design time to add the values, but I don't know why they are not stored properly. Same problem happens if I try to add the values in the code behind using the Add(SizeItem) method, they don't load properly.
I guess it might be a problem with persistance. I'm pretty new to C# and .NET and would really appreciate some help on this. Please feel free to ask any other questions.
Thanks in advanced
|
|
|
|
|
LuKas23_ wrote: following instructions found in several forums,
Did you try looking at the documentation for ASP.NET Custom Controls[^]? Forums are not the best choice for information like that.
led mike
|
|
|
|
|
I did try to look to the documentation you pointed out[^], and also other sites talking about extending ASP Controls. I managed to create a control with a collection property and run in properly with data persitance. The problem is that the collection I have in my GridView control is used to bind a child control (DropDownList) of the GridView, and not the parent control. I don't really know if this can be affecting the normal behaviour, but the thing is that the SizeItemsCollection data doesn't persist.
Maybe I'm going in the wrong direction and the problem is somewhere else, but I hope someone here around TheCodeProject will guide me to the solution.
Thanks
|
|
|
|
|
I have a form view that use objectDataSource with cache enable as following:
<asp:ObjectDataSource ID="odsTest" Runat="server" EnableCaching="true" CacheDuration="300" CacheExpirationPolicy="Sliding" CacheKeyDependency="ckdCaseExam" TypeName="App.Test" SelectMethod="GetTestList" UpdateMethod="fvwTest">
*Assuming the SELECT item1, item2, item3 from tblTest WHERE item4 =’Y’
I need to access the cached data to check something in code behind without refresh the data. How can I do it?
|
|
|
|
|
hi
I have a regular validator for a textbox, I would like the textbox to only accept numeric entry but also allow a .
so it would except the following
1
11
1.1
but not
letter
i have this ([0-9]{1,2}) but I cant find anyway to enter a .
thanks
|
|
|
|
|
sorted it
\d+(\.\d{1,2})?
|
|
|
|
|
Erhm, I'm not a regular expressions wizard... but this may be the one
^([0-9]+)([\.]?)([0-9]*)$
|
|
|
|
|
I have created a web control library but i have the following two major problems:
1- when the page is posted back the control disappears from the page as it is added in the run time. I need it to still as it is and the values in (text boxes or radios).
2- I need to know a mechanism to take the user data entered in the control.
thanks in advance
abdelhameed81
|
|
|
|
|
This is such a common question, I should check if there's an article on it ( I'm sure there is ) and write one if need be
You need to add the control every time, on postback. And you need to add it before page load in order for viewstate to be restored so you can get values from it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|