문제

I have an SQL statement I run for my website that inserts data into an access database. Is there a way during the insert to replace a space " " if one of the date textboxes contains a space? I need to do this because it throws off my date queries if there is a space in one of the columns?

INSERT INTO tblOpen (DateColumn1, DateColumn2) Values (@Value1, @Value2)
도움이 되었습니까?

해결책

You should use the 'datetime' type for your DateColumn. It solves all your problem. It is good to use proper variable for proper field.

다른 팁

If you mean heading and trailing spaces, then:

myString = myString.Trim()

in your vb.net code will be fine. Even though I would follow Steve's suggestion and converting to date.

As question was about replace, you can either use Replace()

INSERT INTO tblOpen (DateColumn1, DateColumn2) 
    Values (REPLACE(@Value1, ' ', ''), @Value2)

or LTrim() and RTrim()

INSERT INTO tblOpen (DateColumn1, DateColumn2) 
    Values (LTRIM(RTRIM(@Value1)), @Value2)

However if datatype is a datetime then it makes sense to convert to that type using

DateTime d = Convert.ToDateTime(TextBox1.Text);
SqlParameter p = command.Parameters.Add("@Value1", System.Data.SqlDbType.DateTime);
p.Value = d;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top