Can't get my table to take data from my form...

wings9697

Member
Joined
Aug 27, 2007
Messages
23
Location
Washington, DC
Programming Experience
10+
Hi all,

I am new at VB.net, so bear with me... :confused: I have built a set of web forms to take in data in reference to investigations. No field manipulation, just straight data entry.

I have tried different ways to get data in, but the info doesn't get posted to the table.

First I tried the Dataset method, but it told me I was referencing a null dataset, but I am able to open it and look at it.
strConn="Server=.\SQLExpress;AttachDbFilename=C:\Projects\mclu_caselog.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"


Dim NewCase As New DataSet
Dim rowNewCase As DataRow
Dim ncSql As New SqlConnection(strConn)

ncSql.Open()

rowNewCase = NewCase.Tables("caselog").NewRow()
rowNewCase("case_cses_num") = TextBox1.Text
rowNewCase("case_agentnum") = TextBox2.Text
rowNewCase("case_ccn") = TextBox3.Text
rowNewCase("case_location") = TextBox7.Text
rowNewCase("case_complname") = TextBox9.Text
rowNewCase("case_compfname") = TextBox10.Text
rowNewCase("case_district") = TextBox4.Text
rowNewCase("case_psa") = TextBox5.Text
rowNewCase("case_leadtechlname") = TextBox11.Text
rowNewCase("case_leadtechfname") = TextBox12.Text
rowNewCase("case_asstechlname") = TextBox15.Text
rowNewCase("case_asstechfname") = TextBox16.Text
rowNewCase("case_leaddetlname") = TextBox13.Text
rowNewCase("case_leaddetfname") = TextBox14.Text
rowNewCase("case_evtdate") = CType(TextBox6.Text, Date)
rowNewCase("case_rptdate") = CType(TextBox19.Text, Date)
rowNewCase("case_off_inc") = TextBox8.Text
rowNewCase("case_photo") = CheckBox1.Checked
rowNewCase("case_evidence") = CheckBox2.Checked
rowNewCase("case_prints") = CheckBox3.Checked
rowNewCase("case_diagram") = CheckBox4.Checked
rowNewCase("case_section") = TextBox17.Text
rowNewCase("case_notes") = TextBox18.Text

NewCase.Tables("caselog").Rows.Add(rowNewCase)

ncSql.Close()

I then tried a straight SqlDataReader method, but it won't accept anything I put in the VALUES clause of my INSERT Sql statement to hold the values of what was entered in the fields on the form.

Dim fconn1, fconn2, fconn3, fconn4, fconn5, fconn6, fconn7, fconn8, fconn9, fconn10, fconn11, _
fconn12, fconn13, fconn14, fconn15, fconn16, fconn17, fconn18, fconn19, fconn20, fconn21, _
fconn22, fconn23 As String
Dim sqlstr1 As String
sqlstr1 = "insert into caselog(case_cses_num,case_agentnum,case_ccn,case_location,case_complname,case_compfname,case_district, " & _
"case_psa,case_leadtechlname,case_leadtechfname,case_asstechlname,case_asstechfname,case_leaddetlname,case_leaddetfname,"& _ "case_evtdate,case_rptdate,case_off_inc,case_photo,case_evidence,case_prints,case_diagram,case_section,case_notes) VALUES " & _
"(TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox7.Text,TextBox9.Text,TextBox10.Text,TextBox4.Text," & _
"TextBox5.Text,TextBox11.Text,TextBox12.Text,TextBox15.Text,TextBox16.Text,TextBox13.Text,TextBox14.Text" & _
"CType(TextBox6.Text, Date),CType(TextBox19.Text, Date),TextBox8.Text,CheckBox1.Checked,CheckBox1.Checked" & _
"CheckBox2.Checked,CheckBox3.Checked,CheckBox4.Checked,TextBox17.Text,TextBox18.Text)"
Dim strConn As String = "Data Source=MPD_IT_5154_002\SQLEXPRESS;Initial Catalog=mclu_caselog;Integrated Security=True"
Dim tbadd As New SqlConnection(strConn)

tbadd.Open()

Dim cmd As SqlCommand = tbadd.CreateCommand()
cmd.CommandText = sqlstr1
Dim rdr As SqlDataReader = cmd.ExecuteReader()

fconn1 = TextBox1.Text
fconn2 = TextBox2.Text
fconn3 = TextBox3.Text
fconn4 = TextBox7.Text
fconn5 = TextBox9.Text
fconn6 = TextBox10.Text
fconn7 = TextBox4.Text
fconn8 = TextBox5.Text
fconn9 = TextBox11.Text
fconn10 = TextBox12.Text
fconn11 = TextBox15.Text
fconn12 = TextBox16.Text
fconn13 = TextBox13.Text
fconn14 = TextBox14.Text
fconn15 = CType(TextBox6.Text, Date)
fconn16 = CType(TextBox19.Text, Date)
fconn17 = TextBox8.Text
fconn18 = CheckBox1.Checked
fconn18 = CheckBox1.Checked
fconn19 = CheckBox2.Checked
fconn20 = CheckBox3.Checked
fconn21 = CheckBox4.Checked
fconn22 = TextBox17.Text
fconn23 = TextBox18.Text

tbadd.Close()

NOTE : I realize putting the TextBox items in the VALUES clause is wrong. They replaced the fconn variables above. I thought, like in older versions of VB, you could take from the form and then flip the values into the table fields via the tablename!fieldname=variable. That failed miserably... but at this point, I am trying just about anything....

When I hit the "cmd.ExecuteReader()", I get a message saying I need the right "Constants" (MSDN was no help here either.... I was referred to constants such as vbCr and vbLF...)

What really drives me nuts, is that if I step through with the debugger, I can see the data coming from the form to the code, but it won't take that last step and go to the table...(lol)

Is this problem caused because I'm not using a "gridview" or "formview" control on my form to group my controls? I've noticed that if I use a gridview control and the controls that come with it, I can add records, so I know the vb can see the table.

Can somebody point me in the right direction? Thanks in advance...
 
Read the DW2 link in my signature, section "Creating a Simple Data App" then section "Creating a Form to Search Data"

Dont try to fit it to your existing app, start over with the example. THen, dump all that code you wrote (sorry, but you're making your life very hard work for yourself; let go the old ways) and write it as DW2 teaches you..
 
Back
Top