|
I'm alone in the dark! HELP!!
|
|
|
|
|
1/ To store the date in that format when entering into the database use this
'DateTime is the name of the variable (this is just for example)
DateTime = Format(DateTime,"yyyy/MM/dd")
This will store it in the format yyyy/mm/dd
2/ Query the database (use a stored procedure as inline SQL is prone to SQLInjection Attacks)
CREATE PROCEDURE DoesDateExist(@Date_Value DATETIME)
AS
SELECT
*
FROM
Table_Name
WHERE
date_value > @Date_Value
AND date_value < DATEADD(day,1,@Date_Value)
This is a simple procedure, you need to create your own according to your data structure, I was just trying to put you on the right path. As for #3, you said you can do that one so I wont answer it Last modified: 44mins after originally posted -- Inadvertanly used the LIKE keyword on a DATETIME field
"Let's face it, the average computer user has the brain of a Spider Monkey."
Bill Gates
|
|
|
|
|
You can use LIKE for a DATETIME ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You're right, I wasn't even thinking
"Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean."
Tom Welch
|
|
|
|
|
What I'm trying to create:
When I click on a date on the date picker, the program will automatically load the status of all tins from a file corrisponding do that date (tsyyyymmdd.xls). Moisture tins (IDed by letter & number) used on that day already will be prevented from selection. The promt to save data (from that date) should come up when a different date is selected (possibly even from the past). And so it goes.
ok, I know this syntax works for SaveAs:
'Save the sheet to c:\LabStore\TinStats folder
xlSheet.SaveAs("c:\LabStore\TinStats\myexcelsheet.xls")
how can I exchange the "myexcelsheet.xls" part for something like "ts20070720.xls"? Being the example date in this instance for 20/07/2007 (Sorry guys Australian Format
The rest of the program is simple physics which I have no trouble with, but this is melting my brain!
|
|
|
|
|
xlSheet.SaveAs("c:\LabStore\TinStats\ts" & format(today(),"yyyyMMdd")& ".xls")
|
|
|
|
|
Thank you Richard, you're a champion!!!
|
|
|
|
|
I'm nearly there!
The today's date works well, but now...
How do I make it save as the date selected (if infact different from the current date such as 2 or 3 days ago as selected by mouse) from the MonthCalendar control?
I've started by declaring,
Public dateChosen As DateFormat
but don't know how to fill "dateChosen" with the (yyyyMMdd) format, so as to insert it in place of the "today" example you gave me earlier.
I know this is all pretty basic stuff, but I'm having a devil of a time trying to find the info anywhere.
Thanks
Rod
|
|
|
|
|
I think the line of code you are looking for is this:
strFilename = "C:\myPath\ts" & Format(Me.MonthCalendar1.SelectionStart, "yyyyMMdd")
Try this this though - in case file exists already...
Dim strFilename As String
Dim strTempFilename As String
Dim i As Integer = 0
strFilename = "C:\myPath\ts" & Format(Me.MonthCalendar1.SelectionStart, "yyyyMMdd")
strTempFilename = strFilename
'Warning if file already Exists
If IO.File.Exists(strTempFilename & ".xls") Then
MessageBox.Show("File already Exists - Allocating a new Filename...")
End If
'If the file exists, then create a new filename, by appending _00, _01 etc
Do While IO.File.Exists(strTempFilename & ".xls")
strTempFilename = strFilename & "_" & i.ToString.PadLeft(2, "0"c)
i += 1
Loop
'Now Save the file
'Excel.SaveAs(strTempFilename & ".xls")
MessageBox.Show("File saved as: " & strTempFilename)
|
|
|
|
|
I have been studying and searching all day and found code similar to my needs but nothing quite fitting. I was experimenting with combinations but pretty much flying blind.
You have been so helpful mate, I don't know the words to thank you!!
Frank
|
|
|
|
|
Hi,
i want to make an html editor in vb.net.
Do anyone knows the reference for my project?
thanx
|
|
|
|
|
First build a simple notepad which opens your html file and save with changes. Then add some patter matching[^] stuff.
--------------------------------
txtSignature
|
|
|
|
|
Hi,
If you need a simple Editor you could use a textbox control (MultiLine=True, Scrollbars=Both), for colored/advanced look, you could use the RichTextBox control, building an Intellisense Engine will require you extra effort, instead you could add a set of controls (menuitems/buttons) which allow users to click on them and select from a pop-up windows the type of tag/value to insert and here you can add some validation from your side. In addition You can use the WebBrowser control to add the feature of WYSIWYG, you could also host the Editor and Viewer (WebControl) on a TabControl. Also you could use the XHTML format and use the XML rules to validate the formatting (Well-fomatted XML Document)
Hope this helps
|
|
|
|
|
I am trying to update the Employees tbl in the northwind db. I want to use code behind to do it, to better understand databinding and how ds's and da's work. I am having an issue actually posting th edata back to the db.
I am using a detailsView to display the information on my page, I am also pulling the infor for the dv from a query string, here is my pageLoad code for my details page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim connStr As String = ConfigurationManager.ConnectionStrings("NWConnectionString").ToString()
' Create DB Connection
Dim conn As New SqlConnection(connStr)
'Create DS
Dim ds As New DataSet
'Read EmployeeID from Default.aspx
Dim sEmployeeId As String = Request.QueryString("EmployeeID")
'Create DA
Dim da As New SqlDataAdapter("SELECT * FROM Employees WHERE [EmployeeID] = " & sEmployeeId, conn)
'Open Conn to DB
conn.Open()
'Fill DA with tbl
da.Fill(ds, "Employees")
'Set DataSource to DataSet
dvDetails.DataSource = ds
'Bind DV to ds
dvDetails.DataBind()
'Close DB Connection
conn.Close()
End If
End Sub
I will post the rest of the code in my next post, to keep the post a little shorter....
|
|
|
|
|
Here is the update logic that I have written:
Protected Sub update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles update.Click
Dim connStr As String = ConfigurationManager.ConnectionStrings("NWConnectionString").ToString()
' Create DB Connection
Dim conn As New SqlConnection(connStr)
'Create Select Statement
Dim strSql As String = "Select * From Employees"
'Create Sql Update Statement
Dim upSql As String = "UPDATE Employees SET LastName=@LastName, FirstName=@FirstName, Title=@Title, Address=@Address," & _
"City=@City, Region=@Region, PostalCode=@PostalCode, HireDate=@HireDate Where EmployeeID=@EmployeeID"
Try
'Create DataAdapter
Dim da As New SqlDataAdapter
da.SelectCommand = New SqlCommand(strSql, conn)
'Create and Fill DataAdapter
Dim ds As New DataSet
da.Fill(ds, "Employees")
'Get the DataTable
Dim dt As DataTable = ds.Tables("Employees")
'Modify the Rows
dt.Rows(0)("LastName") = "@LastName"
dt.Rows(0)("FirstName") = "@FirstName"
dt.Rows(0)("Title") = "@Title"
dt.Rows(0)("Address") = "@Address"
dt.Rows(0)("City") = "@City"
dt.Rows(0)("Region") = "@Region"
dt.Rows(0)("PostalCode") = "@PostalCode"
dt.Rows(0)("HireDate") = "@HireDate"
'Update Employees Table
'Create Command
Dim upCmd As New SqlCommand(upSql, conn)
'Map Parameters
upCmd.Parameters.Add("@LastName", SqlDbType.VarChar, 20, "LastName")
upCmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 10, "FirstName")
upCmd.Parameters.Add("@Title", SqlDbType.VarChar, 30, "Title")
upCmd.Parameters.Add("@Address", SqlDbType.VarChar, 60, "Address")
upCmd.Parameters.Add("@City", SqlDbType.VarChar, 15, "City")
upCmd.Parameters.Add("@Region", SqlDbType.VarChar, 15, "Region")
upCmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 10, "PostalCode")
upCmd.Parameters.Add("@HireDate", SqlDbType.DateTime, 8, "HireDate")
'Map EmployeeID Parameter
Dim idParam As SqlParameter = upCmd.Parameters.Add("@EmployeeID", SqlDbType.Int, 4, "EmployeeID")
idParam.SourceVersion = DataRowVersion.Original
'Open the connection
conn.Open()
'Update Employees Table
da.UpdateCommand = upCmd
ds.AcceptChanges()
da.Update(ds, "Employees")
Catch ex As Exception
'Display Error
Console.WriteLine("Error: " & ex.ToString())
Finally
'Close Connection
conn.Close()
'Redirect to Home
Response.Redirect("~/Default.aspx")
End Try
End Sub
I know it has something to do with passing the data back to the ds, but I am not sure what I am missing. Also, am I referencing an unknown row properly in the 'Modify Rows' section?
Any and all help is appreciated. I think I am close, but not sure what I am missing.
Stupid1
|
|
|
|
|
TextBox1.Text = Replace(SplitTextLineContent, SplitTextLineContent.Substring(SplitTextLineConten t.ToString().IndexOf("V"), SplitTextLineContent.ToString().IndexOf(vbNewLine) ), "")
SplitTextLineContent contains many lines of text.
I would like to replace those char or text that start with "V" until end of the line (vbNewLine) with " ". In other words, take out those text after "V" until the end of the line and replace with blank " ". But the coding above is incorrect. Pls help.
|
|
|
|
|
Hi,
first of all you will not win a special prize for trying to do all your stuff in a single
line of code; instead you will loose points for unintelligible code.
What you need is locate the start point of your string to be replaced (you have that already);
from there, find the next newline (use an overload of IndexOf that lets you specify a starting point);
then perform the necessary replacement, which requires two String.Substring calls (the
Replace method might "hit" several times!).
And you need to handle the special case when no newline is found too.
so in the end that will take about 5 lines of simple code.
|
|
|
|
|
Hi,
whether can show me the example? I don't understand
use an overload of IndexOf that lets you specify a starting point);
then perform the necessary replacement, which requires two String.Substring calls (the
Replace method might "hit" several times!
Your prompt reply will be kindly appreciated. Thanks
|
|
|
|
|
Hi,
this is what I meant in pseudo-code (I cant help it if it looks very much like C#);
myText is the string to be manipulated.
int startIndex=myText.IndexOf(theStringThatMarksTheBeginOfReplace);
if (startIndex>=0) {
int endMarkLen=theStringThatMarksTheEndOfReplace.Length;
int endIndex=myText.IndexOf(theStringThatMarksTheEndOfReplace, startIndex);
if (endIndex<0) myText=text.Substring(0,startIndex);
else myText=myText.Substring(0,startIndex)+myText.SubString(endIndex+endMarkLen);
}
That should do it. I suggest you read MSDN on any method you are unfamiliar with.
|
|
|
|
|
I got another question. If 1 line of text contain 2 "V", i would like to replace those char or text that start with second "V" until end of the line (vbNewLine) with " ". How to do it?
For substring(first_parameter, second_parameter), may i know what is the purpose of second_parameter?
|
|
|
|
|
If you want to find the second occurence, the easiest way is first find the first occurence,
if found, now look for the second (using the start parameter carefully, otherwise
you end up finding the first again); then if found, do what you intended to do.
A lot of methods have (or optionally have) both a start and a length, which means
do it from start up to start+length-1; so substring(start, length) copies part of
a string, with at most length chars copied, the ones in the range [start, start+length-1]
or less, if there arent that many.
You urgently need to get the habit of reading the documentation, either the
local copy of MSDN that comes with Visual Studio, or the MSDN web site that described
everything Microsoft has. Forums like these are not meant for duplicating the
Microsoft documentation.
|
|
|
|
|
If you want to find the second occurence, the easiest way is first find the first occurence,
if found, now look for the second (using the start parameter carefully, otherwise
you end up finding the first again); then if found, do what you intended to do.
A lot of methods have (or optionally have) both a start and a length, which means
do it from start up to start+length-1; so substring(start, length) copies part of
a string, with at most length chars copied, the ones in the range [start, start+length-1]
or less, if there arent that many.
You urgently need to get the habit of reading the documentation, either the
local copy of MSDN that comes with Visual Studio, or the MSDN web site that described
everything Microsoft has. Forums like these are not meant for duplicating the
Microsoft documentation.
And if you need a tutorial, I recommend you look for an introductory book on C#
in your local book shop or at Amazon's web site.
|
|
|
|
|
Dim textdelimiter As String<br />
textdelimiter = " "<br />
<br />
Dim splitout() = Split(TextLineContent, textdelimiter)<br />
<br />
Dim i As Integer<br />
<br />
For i = 0 To UBound(splitout)<br />
<br />
Dim startIndex As Integer<br />
startIndex = splitout(i).IndexOf("V")<br />
<br />
If startIndex >= 0 Then<br />
<br />
Dim endMarkLen = (splitout(i).Length)<br />
<br />
Dim endIndex = splitout(i).IndexOf(splitout(i), startIndex)<br />
<br />
Dim SecondstartIndex As Integer<br />
SecondstartIndex = splitout(i).IndexOf("V", startIndex)<br />
<br />
If (SecondstartIndex >= 0) Then<br />
splitout(i) = splitout(i).Substring(0, SecondstartIndex)<br />
Else<br />
If (endIndex < 0) Then<br />
<br />
splitout(i) = splitout(i).Substring(0, startIndex)<br />
<br />
Else<br />
splitout(i) = splitout(i).Substring(0, startIndex) + splitout(i).Substring(endIndex + endMarkLen)<br />
<br />
End If<br />
End If<br />
<br />
End If<br />
<br />
SplitTextLineContent += Trim(splitout(i)) & " " <br />
<br />
Next i
Hi,
It didn't work. i tried to find the second occurance of "V" and want to store the array from 0 to the second occurance of "V". I have already struggled for few hours.
|
|
|
|
|
Hi,
several comments:
1.
please use the PRE tag to show some code, it preserves indentation, makes things
much more readable on this forum
2.
why does your code contain a dozen splitout(i) ?
it would be much better to use a variable to hold this, say
Dim split As String
split=splitout(i)
this improves readability inside your IDE as well as on this forum
3.
first bug: endMarkLen must equal the length of the thing that marks the end of what you search,
so you can skip it; it could be 1 or 2 (for length of vbCrLf), it certainly is NOT equal
to split.Length
4.
second bug: you search in the wrong order, you must look for V, then for second V,
then for the end-of-line; there is no other way that is guaranteed to work.
Actually looking for a second V only adds 2 lines to the program you had before !
5.
if things dont work as intended, you must search the bugs, that is called debugging.
Lots of people will tell you to use a debugger for that; I tell you to (temporarily) add
some output statements to your code, showing the content of your variables at different
locations in your code.
It may seem like a bit of extra work, the advantage is you get the relevant information
one after another, listed sequentially (as opposed to a debugger that lets you peek into
just everything, but makes it more diffictult to see many things at once, especially
values before and after something has happened.
Hence add "log statements" and study the log; in this case, show startIndex, endIndex,
etc. and check them manually.
6.
And always true: if something does not work as intended, and it seems difficult to manage,
trim it to something smaller that still fails, but is easier to analyze; then debug,
find the mistake, learn from it, and go back to the bigger thing.
Good luck
|
|
|
|
|
Forgot to add: normally a Replace method (say String.Replace) replaces every occurence,
so "aha".Replace("a","o") yields "oho"
dont know what your Replace method does, if it replaces only one occurence, then maybe
you should choose a different name (ReplaceOnce ?).
|
|
|
|
|