Friday, March 9, 2012

Insertion of Data

I am using vs2005 and sqlserver2000My problem is i have 5 checkboxes and some textboxes.In this user selects the checkbox and textboxes dynamically .In this user selects one or two or three or when user selects header checkbox then all checkboxes are selected.And in my database i mentioned a single column for group of checkboes.So how should i insert the data into databasedim con as new sqlconnection("userid=sa;pwd=; initial catalog=test")dim cmd as sql commandProtected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Clickcmd.CommandText = "insert into check values(" what should i write here ...'" & text.text &"','" @. text2.text "'... ")con.open()cmd.executenonquery()con.close()End Subyour insert will majorly depend on the structure of the database.....how r u storing the it in the database...as bits or strings ......be a little more elaborate about the database structure.|||

It looks like you have one column for check boxes, and then one column each for all of the text fields? This depends on that you want to put in the checkbox column, but if you are inserting text to a field for each of the textbox columns and those correspond to a certian checkbox, you will be able to search your table for which textboxes have text for an entry and decide from that which boxes where checked, so you might even be able to just use the checkbox column as your identity (primary key). i.e., data structure like so:

Columns: checkbox / text1 / text2 / text3 / text4

Data: "some number" / "" / "some text" / "" / "some text"

If you were to query that data row above, you would be able to see that the check boxes in question are the ones without null text field rows. However, if you allow null text values you'd have to re-think this method a bit.

Anyway, the checkbox field can be whatever you want, and that will just depend on whatever logic you come up with. You could do it the long way and make a reference table that holds a unique value for each combination of textboxes, but this will get long and messy. Using 1 column to signify a checkbox group might not be the best way to do things, but that's not up to me since it's your data. Anyway, with that setup an insert query something like this might work for you:

"INSERT INTO check (checkBoxField,TextField1,TextField2,TextField3...)VALUES (" & "checkboxNumber" & "," & text1.text & ", " & text2.text & ", " & text3.text & ")"
..where *check* is the table name, and checkboxNumber is whatever you decide to put in the checkbox field.

No comments:

Post a Comment