帮我看下这段代码~~

zj514394212 2010-02-24 02:07:15
Private Sub FrmReg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cboSex.SelectedIndex = 0
classconn.constate()
Button1.Enabled = False
End Sub
Public classconn As New Class1
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("请输入注册帐号", MsgBoxStyle.OkOnly, "错误")
Else
If txtpwd1.Text = "" Then
MsgBox("请输入密码", MsgBoxStyle.OkOnly, "错误")
Else
If txtpwd2.Text = "" Then
MsgBox("重复密码不能为空", MsgBoxStyle.OkOnly, "错误")
Else
If txtpwd1.Text <> txtpwd2.Text Then
MsgBox("两次密码输入不相同,请重新输入", MsgBoxStyle.OkOnly, "错误")
txtpwd1.Focus()
Else
Dim newcommand1 As New SqlCommand With {.CommandText = "select * from QQ账户信息 where QQ号码=" & TextBox1.Text, .Connection = classconn.QqLink}
If newcommand1.ExecuteScalar <> 0 Then
MsgBox("帐号已存在,请更换", MsgBoxStyle.OkOnly, "错误")
TextBox1.Focus()
Else
Dim Country As String = TextBox3.Text
If TextBox3.Text = "" Then
Country = "null"
End If
Dim Section As String = TextBox4.Text
If TextBox4.Text = "" Then
Section = "null"
End If
Dim Old As String = TextBox5.Text
If TextBox5.Text = "" Then
Old = "null"
End If
Dim SexString As String
If cboSex.SelectedText = "男" Then
SexString = "insert into QQ账户信息(QQ号码,QQ密码,性别,国家,地区,年龄) values ('" & TextBox1.Text & "','" & txtpwd1.Text & "','男','" & Country & "','" & Section & "','" & Old & "')"
Else
SexString = "insert into QQ账户信息(QQ号码,QQ密码,性别,国家,地区,年龄) values ('" & TextBox1.Text & "','" & txtpwd1.Text & "','女','" & Country & "','" & Section & "','" & Old & "')"
End If
Dim newcommand2 As New SqlCommand With {.CommandText = SexString, .Connection = classconn.QqLink}
newcommand2.ExecuteScalar()
MsgBox("注册成功")
Me.Close()
End If
End If
End If
End If
End If
End Sub'问题是这样insert的话,数据库里的性别怎么都是女的啊?问题到底在哪里?
...全文
69 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cobra009 2010-02-24
  • 打赏
  • 举报
回复
在If cboSex.SelectedText = "男" Then
前加个msgbox(cboSex.SelectedText)看看出来的是不是男,估计写了男这里也出来的不是男,所以直走else线
cobra009 2010-02-24
  • 打赏
  • 举报
回复
说明If cboSex.SelectedText = "男" Then
这个判断有问题,从来没走过
神之泪花 2010-02-24
  • 打赏
  • 举报
回复
从数据来说,应该直走了else部分,单目调试一下看看吧
戈壁上的月光 2010-02-24
  • 打赏
  • 举报
回复

If cboSex.SelectedText = "男" Then
SexString = "insert into QQ账户信息(QQ号码,QQ密码,性别,国家,地区,年龄) values ('" & TextBox1.Text & "','" & txtpwd1.Text & "','男','" & Country & "','" & Section & "','" & Old & "')"
Else
SexString = "insert into QQ账户信息(QQ号码,QQ密码,性别,国家,地区,年龄) values ('" & TextBox1.Text & "','" & txtpwd1.Text & "','女','" & Country & "','" & Section & "','" & Old & "')"
End If


跟踪调试该部分,条件判断可能只是满足else部分
zj514394212 2010-02-24
  • 打赏
  • 举报
回复
我在数据库里这样查询就是男的
insert into QQ账户信息(QQ号码,QQ密码,性别,国家,地区,年龄) values('0987','qweq','男','gdgd','rgter','11')
说明语句没问题吧
zj514394212 2010-02-24
  • 打赏
  • 举报
回复
还是没看出个名堂来,结果数据库里还是女的
水猿兵团五哥 2010-02-24
  • 打赏
  • 举报
回复
用代码逐步调试下看看

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧