Asp.net vb网页制做问题
我想做一个留言版,怎么将cookie变量插入数据库,这个是插入按钮代码:SubSure_Click(SenderAsObject,EAsEventargs)DimCnnA...
我想做一个留言版,怎么将cookie变量插入数据库,这个是插入按钮代码:
Sub Sure_Click(Sender As Object,E As Eventargs)
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim StrCnn As String
Dim Sql As String
Dim theTitle As String = title.Text
Dim theQQ As String = QQCode.Text
Dim theHomePage As String = homepage.Text
Dim theContent As String = Content.Text
Dim theLyr As String = Request.Cookies("name").value(这里老提示错误!)
Dim theEmail As String = Request.Cookies("emm").value(这里老提示错误!)
Dim theFace As String = selface.SelectedItem.Value
StrCnn = System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Cnn")
Cnn = New OleDbConnection(StrCnn)
Cnn.Open()
Sql = "insert into lyinfo(name,qq,email,homepage,title,content,faceid) values('" & Trim(theLyr) & "','" & Trim(theQQ) & "','" & Trim(theEmail) & "','" & Trim(theHomePage) & "','" & Trim(theTitle) & "','" & Trim(theContent) & "'," & Trim(theFace) & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
Cnn.Close()
Response.Redirect("lyb.aspx")
end sub
这里的cookie变量我在登录的时候定义的,但到这里想插入数据库就不行了,说什么system.NullReferenceException未将对象引用设置到对象实例,还有什么解决的办法么?? 展开
Sub Sure_Click(Sender As Object,E As Eventargs)
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim StrCnn As String
Dim Sql As String
Dim theTitle As String = title.Text
Dim theQQ As String = QQCode.Text
Dim theHomePage As String = homepage.Text
Dim theContent As String = Content.Text
Dim theLyr As String = Request.Cookies("name").value(这里老提示错误!)
Dim theEmail As String = Request.Cookies("emm").value(这里老提示错误!)
Dim theFace As String = selface.SelectedItem.Value
StrCnn = System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Cnn")
Cnn = New OleDbConnection(StrCnn)
Cnn.Open()
Sql = "insert into lyinfo(name,qq,email,homepage,title,content,faceid) values('" & Trim(theLyr) & "','" & Trim(theQQ) & "','" & Trim(theEmail) & "','" & Trim(theHomePage) & "','" & Trim(theTitle) & "','" & Trim(theContent) & "'," & Trim(theFace) & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
Cnn.Close()
Response.Redirect("lyb.aspx")
end sub
这里的cookie变量我在登录的时候定义的,但到这里想插入数据库就不行了,说什么system.NullReferenceException未将对象引用设置到对象实例,还有什么解决的办法么?? 展开
3个回答
展开全部
把Request.Cookies("name").value改为Request.Cookies("name").ToString()试试,如果有数据,应该是数据类型的问题,你前面声明的是string类型,后面也转为string类型。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加上判断 看下Cookies是否是空值 如果不是空值 进行赋值 否则不做操作
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个好像是空值引发的异常。需要IF
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询