vb.net中总结一下关于表单提交类的东西

(1)首先在客户端验证一下,即用按钮的onClientClick在js中验证一下,对于验证一般是验证其是否符合其正则表达式或者是否能为空,然后在服务器端再验证,验证是否为空之类的,最后做插入,删除的数据库处理。
(2)在vb.net中对数据库做读取处理时,首先先if dr.hasRows 判断其是否有内容,然后在做读取的处理,如下面的源代码:
If dr.HasRows Then
            Do While dr.Read()
                Response.Write(dr("标题"))
                Response.Write("<div class='xinWenXianShi1_1_1'>")
                Response.Write("<a target='_blank' href='xinWenXianShi2.aspx?bianHao=" & dr("编号") & "'>" & dr("标题") & "</a>")
                Response.Write("<span class='xinWenXianShi1_1_1_1'>")
                Response.Write("[" + dr("发布时间") + "]")
                Response.Write("</span>")
                Response.Write("</div>")
            Loop
        End If

(3)做插入操作时,必须用if语句做判断确定插入后在执行别的操作,代码如下:
If myCommand.ExecuteNonQuery() <> "" Then   '写入数据
Response.Write(" <script>{window.location='fbchenggong.aspx'} </script>")
End If
而且,打开的reader和connection 最后都要关闭,即:
dr.Close()    '关闭reader
        myConnection.Close()   '关闭与数据库的连接
 

你可能感兴趣的:(表单,VB.NET)