|
-
Oct 9th, 2002, 04:46 AM
#1
Thread Starter
Addicted Member
how to save to a diff db structure
i have 3 combo boxes in a form. One is binded to a dataset and the other 2 are constants defined in the item collection. The name of the fields are group(databound combobox), dayofweek(Monday, tue, etc..) and time (12:00am, 1:30am...and so on).
My question is how to save the information in a database with this structure: grp, mon, tue, wed, thu, fri. The value from the databound combobox will be save to grp. Then the value from time combobox will be save to mon, tue, wed, thu fri depending on the value from the dayofweek combobox.
For example:
grp: Accessories
dayofweek: Monday
Time: 12:00n
The db will be:
grp:Accessories
mon:12:00nn
tue:<null>
wed:<null>
thu:<null>
fri:<null>
Im just starting to learn the .net and Im having a hard time figuring out where and how to start.
Hope somebody out there could give me an idea.
Thanks,
Marivic
-
Oct 9th, 2002, 10:26 AM
#2
When you go to save it to the DB just use the one value as the name of the field to put the other value in. Although it would be easier if the filedname matched the Weekday name exactly (i.e. Monday instead of Mon)
VB Code:
dr.Item(DayOfWeek.GetName(GetType(DayOfWeek), cboDayOfWeek.SelectedValue)) = cboTime.SelectedValue
Also if your combos aren't set up to use the Item Value the just change SelectedValue in the code to whatever way you are storing the values of the items.
-
Oct 9th, 2002, 10:13 PM
#3
Thread Starter
Addicted Member
hi edneeis,
thanks.
this is my code for saving records. i cant figure out where and how can i put your code on.
strSQL = "INSERT into calendar1 ( grpcode " & "," &
cbdayofweek.SelectedItem.text & ")" & _
"values (" & cbgroup.ValueMember & "," & _
txttime.Text & ")"
sample data:
grp:Acessories (grpcode:01)
dayofweek:Monday
time:10:00am
insert stmt shld be:
insert into calendar1(grpcode, monday) values ("01", "10:00am")
grpcode is the value member of cbgroup. how can i construct my insert statement correctly?
Thanks again,
Marivic
-
Oct 9th, 2002, 11:10 PM
#4
Thread Starter
Addicted Member
sorry, it should be
cbgroup.SelectedValue
-
Oct 9th, 2002, 11:25 PM
#5
Is the first filed actually called grpcode? And are the values suppose to be strings?
It looks almost right. If the actual field name is grpcode then it should be this:
strSQL = "INSERT into calendar1 ( "grpcode ," &
cbdayofweek.SelectedItem.text & ")" & _
"values ("' & cbgroup.ValueMember & '","' & _
txttime.Text & "')"
Also it might be hard to see but you have to enclose string values in the values part in single quotes.
-
Oct 10th, 2002, 12:13 AM
#6
Thread Starter
Addicted Member
hi,
sorry, actually i've revised my form. currently, it has 4 combo boxes now, 1 combox is databound.
grpcode is the value member of the grp description which i wanted to save in my db.
cbfromtime and cbtotime are populated from the items collection. (properties). they are of type varchar(30). values are from 8:00 am to 6:00 pm with a 30 minutes interval.
this is now my revised code:
strTime = cbfromtime.SelectedItem.ToString() & " - " & cbtotime.SelectedItem.ToString()
strSQL = "INSERT into calendar2 ( grpcode" & "," & cbdayofweek.SelectedItem.ToString() & ")" & _
"values (" & cbgroup.SelectedValue & "," & CStr(strTime) & ")"
so when this sql is run, the value that shld be saved should be
grp: 01
monday: 8:30 am - 11:00 am
however, ive got an sql error: SQL syntax error near ":"
i understand that since monday field is of type varchar, this shouldn't be a problem. ive tried running this in the sql query analyzer and it goes fine. what's wrong here?
thanks again.
-
Oct 10th, 2002, 12:45 AM
#7
Maybe its the datatype of cbgroup.SelectedValue? Try cbgroup.SelectedValue.ToString or CStr(cbgroup.SelectedValue)
-
Oct 10th, 2002, 01:03 AM
#8
Thread Starter
Addicted Member
ive tried it but the error is still there. i think the error is in the cbfromtime or cbtotime, they have ":" on the value. Ex. 10:30 am...But since its varchar, it shld be accepted. Does colon ( in the value a problem in SQL Server?
-
Oct 10th, 2002, 01:39 AM
#9
As long as its in quotes then it shouldn't be trouble. I wonder what the problem is. Is the length too long for the field?
-
Oct 10th, 2002, 08:20 PM
#10
Thread Starter
Addicted Member
Hi Edneeis,
ive already got the answer. you're correct, since the field is char, then it shld be enclosed in single quotes. I just placed the quotes in the wrong place.
Thanks very much.
-
Oct 10th, 2002, 09:08 PM
#11
Good I'm glad that is all it was. Glad to help anytime.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|