Generate odd number to be added as parameter into sql statement vb.net -
i working in vb.net windows form applications sql end. trying use loop write odd numbers sql column starting 1 , moving amount of rows in datagridview. however, statement not giving me next step , depending on loop placements either miss loop write rows sql database or miss odd number. here code:
cn integer = 0 datagridview1.rowcount - 1 dim starttime date = datagridview1.rows(cn).cells(1).value integer = 1 cn 'sql code try using conn1 new sqlconnection(connstring) conn1.open() using comm1 new sqlcommand("insert table1 (col1, col2, col3, col4, col5) values (@col1, @col2, getdate(), 5, @col5)", conn1) comm1.parameters .addwithvalue("@col1", starttime) .addwithvalue("@col2", combobox1.selectedvalue) .addwithvalue("@col5", i) end comm1.executereader() end using conn1.close() end using catch ex exception msgbox(ex.tostring) end try next next
if understand requirements write this
for cn integer = 1 datagridview1.rowcount dim starttime date = datagridview1.rows(cn-1).cells(1).value try using conn1 new sqlconnection(connstring) conn1.open() using comm1 new sqlcommand("insert table1 (col1, col2, col3, col4, col5) values (@col1, @col2, getdate(), 5, @col5)", conn1) comm1.parameters .addwithvalue("@col1", starttime) .addwithvalue("@col2", combobox1.selectedvalue) .addwithvalue("@col5", (cn * 2) - 1) end comm1.executereader() end using end using catch ex exception msgbox(ex.tostring) end try next
as side note, please read can stop using addwithvalue already?