I'm bulding document-from-template engine. At certain points I need to match on Reg Exp groups and replace template text with content from a db.
I 'hardcoded' my RegExp initially, doing something like: Regex r = new Regex(@"{DocSectionToggle::(?<ColumnName>w+)::(?<ResponseValue>.+)}[[(?<SectionContent>.+)]]", RegexOptions.Multiline);
it does group capture, so the syntax isn't the prettiest.
Just to make things neater and because I want' to keep the patterns in web.config or elsewhere, I've 'evolved' algorithm to something like:
[code]...
But I'm getting an error: 'Input string was not in correct format'.
I am trying to insert "Date" and "Time" in database table (both are separate columns) using below code:
string query = "Insert into tempTable(List_Id, Date, Time) VALUES('" + lblId.Text + "', @Date, @Time)"; SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); TimeSpan time = new TimeSpan(); time.ToString(); cmd.Parameters.AddWithValue("@Date", Convert.ToDateTime(DateTime.Now.ToShortDateString())); cmd.Parameters.AddWithValue("@Time", Convert.ToDateTime(DateTime.Now.ToString("HH:mm:ss"))); cmd.ExecuteNonQuery(); connection.Close();
Above record is inserted in DB like below:In Date column: 12/29/2014 12:00:00 AMIn Time column:12/29/2014 5:30:46 PMDatatype for "Date" and "Time" column is "datetime"I want that: as I save the Date and Time in DB table, it should display same date and same time what is saved in DB table not current date and time.I tried below code to fetch saved records from table, after inserting Date and Time in DB:
string query2 = "Select Date, Time where Id='" + itemId + "'"; SqlCommand cmd2 = new SqlCommand(query2, connection); connection.Open(); SqlDataAdapter da = new SqlDataAdapter(query2, connection); DataTable dt = new DataTable(); da.Fill(dt); lblDate.Text = DateTime.Parse(dt.Rows[0][0].ToString()).ToString("dd-MM-yyyy"); lblTime.Text = DateTime.Parse(dt.Rows[0][1].ToString()).ToString("HH:MM tt");
But currently it is giving me below output : Date:29-12-2014Time:18:04 PM (current time)..
Why its showing current date time in place of saved record ??
I'm concatenating a string in codebehind to use in a sql select statement.
in aspx
<asp:Label ID="LabelHidden" runat="server" Visible="False"></asp:Label> SelectCommand="SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)" <SelectParameters> <asp:ControlParameter ControlID="DropDownList_Employees" Name="ID" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="LabelHidden" Name="ActivityName" Type="String" /> </SelectParameters> in codebehind foreach (ListItem li in ListBox_Activities.Items) { if (li.Selected) { queryBuilder += li + "', "; } queryBuilder = queryBuilder.Substring(0, queryBuilder.Length - 1); LabelHidden.Text = queryBuilder;
When i run the code it comes up blank. I did a query trace and it seems to be running as
exec sp_executesql N'SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)',N'@EmployeeID int,@ActivityName nvarchar(50)',@EmployeeID=4,@ActivityName=N'Production Technical Support'', Tools Development'','
with exta "'s
How can i format the queryBuilder string correctly in my code?
I have project in development where string operations like "Hi " + variable + ", welcome to Project" are used at many places (given example is very minor one).
One of the requirement is to convert it to string.format style.
It is very long and tedious job, where I would not like to break earlier working code due to any human error might happen while converting it.
I would like to if any Macro or VS command which I can create to handle it. Just like we mark block of code and do Extract function in Re-factor options.
I have a displayFormat pattern "$###,###,###;-$###,###,###;#"( it can be different too) and I want to reformat the value in the AspxTextbox after deleting the ',' on GotFocus and LostFocus events by calling the following JavaScript function :
[code]....
I have tried to use ASPxFormatter but it is an internal class that is not indented to be used in a user project.Using String.Format('{0:' + displayFormat + '}', parseInt(value))); didn't work too , it threw an exception since String.format doesn't accept this format of pattern,Can you provide a way to reformat my string to any pattern I want not only the one I recite since ?
i'm developing a website. i have a registration form where user can registered with this website. this have a birthdate field for store user's birthdate.that is a textbox. here is my code.
In a simple ASPX page, I have an SqlDataSource and a DataList control bound to it.It shows 3 columns; UserName, DateTimeStamp, and Comment.The database table has these defined as nvarchar(24), datetime, and nvarchar(80).The UserName and DateTimeStamp are shown in the ItemTemplate as Labels, while the Comment is a multiline TextBox.I have an event handler for the OnTextChanged for the Comment so that I can update the table as soon as the user tabs off the TextBox.I use the UserName and DateTimeStamp as the Primary Key, and pass all 3 to a stored procedure, where the parameters are declared the same types as the table.What I'm getting though is an "Input string was not in the correct format", which can only be the DateTime that I am passing.
I've tried different date/time formats, but so far come up empty as to the one that will actually work from the C# code.All the different formats I've tried work fine if I pass them to the SP directly via Management Studio, but all throw an error when I use
I have a textbox control with a calendarExtender. I want to make the user select a date subsequent to Today. I have a public function, called display_error, written that displays some text in case of validation not successfull. So in this case, the validation of the date inserted by user would look like [Code]....
So, my textBox.text is a string, which I need to convert to Date to compare it to Today. Here's what I've written [Code]....
I've tried different methods, like Parse, but I keep getting the same error, String was not recognized as valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
am using C# ASP. NET 2.0. I have a string that has 4 parts that are separated by a '_' and here is what I want to do:Find the 3rd part of the string and change '-' to '/' in that string.Example: The string may be as shown: 100_John Doe_01-22-2010_08-00-00.txtI want to be able to pull out the date - in this example it is 01-22-2010, and then change the '-' in that string to '/' and display the
I'm getting "the input string was not in the specified format" on the last line of code below. The grid is based on a SqlDataSource that has a stored procedure pulling an integer for column 0.
I create a project on my local host (xp) that work o.k.
I up load the project to the test server (win Server 2008), work o.k.
But when I up load the project to the production server (win Server 2008). It gets that exception(Line 303):
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.