最近在做调查管理的,写的不好,还需努力!
前台
Imports
System.Data
Imports System.Data.SqlClient
Partial Class index Class index
Inherits System.Web.UI.Page
Dim myid As Integer
Protected Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then Dim myQuestion As New quest
Dim myreader As SqlDataReader
myreader = myQuestion.RetriveReader
If myreader.Read Then
lbshow.Text = myreader("QuestionContent")
myid = myreader("QuestionId")
llId.Text = myid.ToString
End If
Dim myanswer As New answer
myanswer.QuestionId = myid
RadioButtonList1.DataSource = myanswer.RetriveDs
RadioButtonList1.DataTextField = "AnswerContent"
RadioButtonList1.DataValueField = "AnswerId"
RadioButtonList1.DataBind()
'RadioButtonList1.SelectedIndex = 0
End If
End Sub
Protected Sub Button1_Click()Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myanswer As New answer(CInt(RadioButtonList1.SelectedValue))
With myanswer
.DianJi = .DianJi + 1
.update()
End With
End Sub
End Class
quest.vb
Imports System.Data.SqlClient
Partial Class index Class index
Inherits System.Web.UI.Page
Dim myid As Integer
Protected Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then Dim myQuestion As New quest
Dim myreader As SqlDataReader
myreader = myQuestion.RetriveReader
If myreader.Read Then
lbshow.Text = myreader("QuestionContent")
myid = myreader("QuestionId")
llId.Text = myid.ToString
End If
Dim myanswer As New answer
myanswer.QuestionId = myid
RadioButtonList1.DataSource = myanswer.RetriveDs
RadioButtonList1.DataTextField = "AnswerContent"
RadioButtonList1.DataValueField = "AnswerId"
RadioButtonList1.DataBind()
'RadioButtonList1.SelectedIndex = 0
End If
End Sub
Protected Sub Button1_Click()Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myanswer As New answer(CInt(RadioButtonList1.SelectedValue))
With myanswer
.DianJi = .DianJi + 1
.update()
End With
End Sub
End Class
Imports
System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Public Class quest Class quest
Private _QuestionId As Integer
Private _QuestionContent As String
Private _CheckIf As Boolean
Private _connstr As String
Sub New()Sub New()
getconnstr()
End Sub
Public Property QuestionId()Property QuestionId() As Integer
Get
Return _QuestionId
End Get
Set(ByVal value As Integer)
_QuestionId = value
End Set
End Property
Public Property QuestionContent()Property QuestionContent() As String
Get
Return _QuestionContent
End Get
Set(ByVal value As String)
_QuestionContent = value
End Set
End Property
Public Property connstr()Property connstr() As String
Get
Return _connstr
End Get
Set(ByVal value As String)
_connstr = value
End Set
End Property
Public Property CheckIf()Property CheckIf() As Boolean
Get
Return _CheckIf
End Get
Set(ByVal value As Boolean)
_CheckIf = value
End Set
End Property
Sub New()Sub New(ByVal QuestionId As Integer)
getconnstr() '得到数据库的连接串
Dim sqlstr As String = "select * from my_question where QuestionId=" + QuestionId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Dim myreader As SqlDataReader
myreader = Com.ExecuteReader
If myreader.Read Then
_QuestionId = QuestionId
_QuestionContent = myreader("QuestionContent")
End If
myreader.Close()
End Sub
Public Function RetriveReader()Function RetriveReader() As SqlDataReader
Dim strSqlstr As String = "select * from my_question where CheckIf=1"
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strSqlstr, Conn)
'验证
Return Com.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Function retrive()Function retrive() As DataSet
getconnstr() '得到数据库的连接串
Dim sqlstr As String
sqlstr = "select * from my_question "
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim da As New SqlDataAdapter(sqlstr, Conn)
Dim ds As New DataSet
da.Fill(ds)
da.Dispose()
Conn.Close()
Return ds
End Function
Public Sub getconnstr()Sub getconnstr()
_connstr = ConfigurationManager.AppSettings("connStr")
End Sub
End Class
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Public Class quest Class quest
Private _QuestionId As Integer
Private _QuestionContent As String
Private _CheckIf As Boolean
Private _connstr As String
Sub New()Sub New()
getconnstr()
End Sub
Public Property QuestionId()Property QuestionId() As Integer
Get
Return _QuestionId
End Get
Set(ByVal value As Integer)
_QuestionId = value
End Set
End Property
Public Property QuestionContent()Property QuestionContent() As String
Get
Return _QuestionContent
End Get
Set(ByVal value As String)
_QuestionContent = value
End Set
End Property
Public Property connstr()Property connstr() As String
Get
Return _connstr
End Get
Set(ByVal value As String)
_connstr = value
End Set
End Property
Public Property CheckIf()Property CheckIf() As Boolean
Get
Return _CheckIf
End Get
Set(ByVal value As Boolean)
_CheckIf = value
End Set
End Property
Sub New()Sub New(ByVal QuestionId As Integer)
getconnstr() '得到数据库的连接串
Dim sqlstr As String = "select * from my_question where QuestionId=" + QuestionId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Dim myreader As SqlDataReader
myreader = Com.ExecuteReader
If myreader.Read Then
_QuestionId = QuestionId
_QuestionContent = myreader("QuestionContent")
End If
myreader.Close()
End Sub
Public Function RetriveReader()Function RetriveReader() As SqlDataReader
Dim strSqlstr As String = "select * from my_question where CheckIf=1"
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strSqlstr, Conn)
'验证
Return Com.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Function retrive()Function retrive() As DataSet
getconnstr() '得到数据库的连接串
Dim sqlstr As String
sqlstr = "select * from my_question "
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim da As New SqlDataAdapter(sqlstr, Conn)
Dim ds As New DataSet
da.Fill(ds)
da.Dispose()
Conn.Close()
Return ds
End Function
Public Sub getconnstr()Sub getconnstr()
_connstr = ConfigurationManager.AppSettings("connStr")
End Sub
End Class
answer.vb
Imports
System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Public Class answer Class answer
Private _AnswerId As Integer
Private _AnswerContent As String
Private _QuestionId As Integer
Private _connstr As String
Private _DianJi As Integer
Sub New()Sub New()
getconnstr()
End Sub
Sub New()Sub New(ByVal AnswerId As Integer)
getconnstr() '得到数据库的连接串
Dim sqlstr As String = "select * from my_answer where AnswerId=" + AnswerId.ToString
Dim conn As New SqlConnection(_connstr)
conn.Open()
Dim com As New SqlCommand(sqlstr, conn)
Dim myreader As SqlDataReader
myreader = com.ExecuteReader
If myreader.Read Then
_AnswerId = AnswerId
_AnswerContent = myreader("AnswerContent")
_DianJi = myreader("DianJi")
_QuestionId = myreader("QuestionId")
End If
myreader.Close()
End Sub
Public Property AnswerId()Property AnswerId() As Integer
Get
Return _AnswerId
End Get
Set(ByVal value As Integer)
_AnswerId = value
End Set
End Property
Public Property AnswerContent()Property AnswerContent() As String
Get
Return _AnswerContent
End Get
Set(ByVal value As String)
_AnswerContent = value
End Set
End Property
Public Property QuestionId()Property QuestionId() As Integer
Get
Return _QuestionId
End Get
Set(ByVal value As Integer)
_QuestionId = value
End Set
End Property
Public Property DianJi()Property DianJi() As Integer
Get
Return _DianJi
End Get
Set(ByVal value As Integer)
_DianJi = value
End Set
End Property
Public Sub update()Sub update()
Dim sqlstr As String = "Update my_answer set AnswerContent='" + _AnswerContent + "',DianJi=" + _DianJi.ToString + ",QuestionId=" + _QuestionId.ToString + "where AnswerId=" + _AnswerId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Com.ExecuteNonQuery()
Conn.Close()
End Sub
Public Sub getconnstr()Sub getconnstr()
_connstr = ConfigurationManager.AppSettings("connStr")
End Sub
Public Function checklogin()Function checklogin() As Integer
'对密码加密
'到数据库验证
'dim strSqlstr as String="select * from Portal_User where UserName='' and userPassword=''"
'' Dim strJiaMi As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(myuserpassword, "sha1")
Dim strsqlstr As String = "select * from my_answer where AnswerContent='" + _AnswerContent + "'"
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strsqlstr, Conn)
'验证
Dim myreader As SqlDataReader = Com.ExecuteReader()
If myreader.Read Then
myreader.Close()
Conn.Close()
Return 1
Else
myreader.Close()
Conn.Close()
Return 0
End If
' myreader.Close()
End Function
Public Function RetriveReader()Function RetriveReader() As SqlDataReader
Dim strSqlstr As String = "select * from my_answer where QuestionId=" + _QuestionId.ToString
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strSqlstr, Conn)
'验证
Return Com.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Function RetriveDs()Function RetriveDs() As DataSet
Dim strSqlstr As String = "select * from my_answer where QuestionId=" + _QuestionId.ToString
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim da As New SqlDataAdapter(strSqlstr, Conn)
Dim ds As New DataSet
da.Fill(ds)
da.Dispose()
Conn.Close()
Return ds
End Function
Public Sub Create()Sub Create()
Dim sqlstr As String
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
sqlstr = "insert into my_answer(AnswerContent,QuestionId) values('" + _AnswerContent + "'," + _QuestionId.ToString + ")"
'需要增加
Dim Com As New SqlCommand(sqlstr, Conn)
Com.CommandText = sqlstr
Com.Connection = Conn
Com.ExecuteNonQuery()
Conn.Close()
End Sub
Public Sub delete()Sub delete()
Dim sqlstr As String = "delete from my_answer where AnswerId=" & _AnswerId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Com.ExecuteNonQuery()
Conn.Close()
End Sub
End Class
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Public Class answer Class answer
Private _AnswerId As Integer
Private _AnswerContent As String
Private _QuestionId As Integer
Private _connstr As String
Private _DianJi As Integer
Sub New()Sub New()
getconnstr()
End Sub
Sub New()Sub New(ByVal AnswerId As Integer)
getconnstr() '得到数据库的连接串
Dim sqlstr As String = "select * from my_answer where AnswerId=" + AnswerId.ToString
Dim conn As New SqlConnection(_connstr)
conn.Open()
Dim com As New SqlCommand(sqlstr, conn)
Dim myreader As SqlDataReader
myreader = com.ExecuteReader
If myreader.Read Then
_AnswerId = AnswerId
_AnswerContent = myreader("AnswerContent")
_DianJi = myreader("DianJi")
_QuestionId = myreader("QuestionId")
End If
myreader.Close()
End Sub
Public Property AnswerId()Property AnswerId() As Integer
Get
Return _AnswerId
End Get
Set(ByVal value As Integer)
_AnswerId = value
End Set
End Property
Public Property AnswerContent()Property AnswerContent() As String
Get
Return _AnswerContent
End Get
Set(ByVal value As String)
_AnswerContent = value
End Set
End Property
Public Property QuestionId()Property QuestionId() As Integer
Get
Return _QuestionId
End Get
Set(ByVal value As Integer)
_QuestionId = value
End Set
End Property
Public Property DianJi()Property DianJi() As Integer
Get
Return _DianJi
End Get
Set(ByVal value As Integer)
_DianJi = value
End Set
End Property
Public Sub update()Sub update()
Dim sqlstr As String = "Update my_answer set AnswerContent='" + _AnswerContent + "',DianJi=" + _DianJi.ToString + ",QuestionId=" + _QuestionId.ToString + "where AnswerId=" + _AnswerId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Com.ExecuteNonQuery()
Conn.Close()
End Sub
Public Sub getconnstr()Sub getconnstr()
_connstr = ConfigurationManager.AppSettings("connStr")
End Sub
Public Function checklogin()Function checklogin() As Integer
'对密码加密
'到数据库验证
'dim strSqlstr as String="select * from Portal_User where UserName='' and userPassword=''"
'' Dim strJiaMi As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(myuserpassword, "sha1")
Dim strsqlstr As String = "select * from my_answer where AnswerContent='" + _AnswerContent + "'"
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strsqlstr, Conn)
'验证
Dim myreader As SqlDataReader = Com.ExecuteReader()
If myreader.Read Then
myreader.Close()
Conn.Close()
Return 1
Else
myreader.Close()
Conn.Close()
Return 0
End If
' myreader.Close()
End Function
Public Function RetriveReader()Function RetriveReader() As SqlDataReader
Dim strSqlstr As String = "select * from my_answer where QuestionId=" + _QuestionId.ToString
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(strSqlstr, Conn)
'验证
Return Com.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Function RetriveDs()Function RetriveDs() As DataSet
Dim strSqlstr As String = "select * from my_answer where QuestionId=" + _QuestionId.ToString
'连接数据库
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim da As New SqlDataAdapter(strSqlstr, Conn)
Dim ds As New DataSet
da.Fill(ds)
da.Dispose()
Conn.Close()
Return ds
End Function
Public Sub Create()Sub Create()
Dim sqlstr As String
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
sqlstr = "insert into my_answer(AnswerContent,QuestionId) values('" + _AnswerContent + "'," + _QuestionId.ToString + ")"
'需要增加
Dim Com As New SqlCommand(sqlstr, Conn)
Com.CommandText = sqlstr
Com.Connection = Conn
Com.ExecuteNonQuery()
Conn.Close()
End Sub
Public Sub delete()Sub delete()
Dim sqlstr As String = "delete from my_answer where AnswerId=" & _AnswerId.ToString
Dim Conn As New SqlConnection(_connstr)
Conn.Open()
Dim Com As New SqlCommand(sqlstr, Conn)
Com.ExecuteNonQuery()
Conn.Close()
End Sub
End Class