'''两段程序就是利用.net的连接对象的功能来完成登录的实例
成都创新互联是专业的额敏网站建设公司,额敏接单;提供网站制作、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行额敏网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click 'start按钮触发的函数
Dim schclass As String = Trim(txtClass.Text) ‘将txtClass里文本赋值给变量schclass
Dim selestr As String
’提示用户txtClass文本框不能为空
If schclass "" Then
selestr = "班级='" schclass "'"
Else
MsgBox("请输入班级名称", 64, "提示") ‘ 显示保存成功提示信息
End If
‘创建一个DataView对象,即将数据集DataSet11里的学生成绩表的DefaultView实例化
Dim dvresult As DataView = DataSet11.学生成绩.DefaultView
’按学号字段排序
dvresult.Sort = "学号"
‘按刚才txtClass里输入的班级查询
dvresult.RowFilter = selestr
dvresult.RowStateFilter = DataViewRowState.CurrentRows
’然后将筛选的结果输入到datagrid上
DataGrid1.DataSource = dvresult
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click ‘ok按钮触发的函数
’如果txtUserName或txtPass文本框为空,提示并中断函数
If txtUserName.Text = "" Or txtPass.Text = "" Then
Response.Write("script language=vbscriptalert""用户名或密码不能为空!""/script")
Exit Sub
End If
‘定义链接、执行、阅读 对象
Dim mycon As New OleDbConnection
Dim mycmd As New OleDbCommand
Dim reader As OleDbDataReader
’给连接对象赋值连接字符串,access类型的。
mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
Server.MapPath("Msg.mdb")
‘打开连接对象
mycon.Open()
’将连接对象复制到执行对象上
mycmd.Connection = mycon
‘然后就给执行对象赋值执行类型和执行语句
mycmd.CommandType = CommandType.Text
mycmd.CommandText = "Select * from myuser Where 用户名='" txtUserName.Text "'" " and 密码='" txtPass.Text "'"
’然后将执行对象的监听实例化
reader = mycmd.ExecuteReader()
‘如果执行不成功,即没有得到结果集就提示否则将结果集的用户名赋值给一个session以供其他页面使用
If reader.Read = False Then
Response.Write("script language=vbscriptalert""用户名或密码错,你不能登录!""/script")
Else
Session("username") = reader("用户名")
Response.Redirect("lwmsg.aspx")
End If
’关闭监听
reader.Close()
‘关闭连接
mycon.Close()
End Sub
顺序应该是先Connection的Open
con.ConnectionString = constr
con.Open()
dc = New OleDbDataAdapter(sql, constr)
另外你的SQL语句好像有点问题,表名不加单引号
你这是vb.net的代码,vb中不允许那么写:
Dim
strdx()
As
String
=
{"0",
"0",
"0"}
'定义个数组,从后面的值能看的出最大下标是2,也就是strdx(0),strdx(1)和strdx(2),3个的默认值都为0
Dim
calcount1
As
String
=
"0"
'定义个字符串变量
Dim
calcount2
As
String
=
"0"
Dim
strvalue
As
Boolean
=
False
'定义strvalue为bool值,改类型变量只有true和false
2种值
If
strdx(0)
=
"0"
Then
TextBox1.Text
=
strdx(0)
"."
这是字符串连接符号,和"+"的区别是,他把左右2边的内容直接连接的,而"+"可能会编程运算符,例如
2
3
=
"23"
而
2
+
3
=
5
ElseIf
strvalue
=
False
Then
strdx(0)
=
strdx(0)
"0"
TextBox1.Text
=
strdx(0)
"."
strvalue
=
True
Else
strdx(0)
=
strdx(0)
"0"
TextBox1.Text
=
strdx(0)
Select
Case
calcount1
'
这里开始是分支语句
Case
"+"
TextBox1.Text
=
Str(Val(strdx(1))
+
Val(strdx(0)))
Dim Cnn As New Data.OleDb.OleDbConnection
Dim DbAdapter As New Data.OleDb.OleDbDataAdapter
Dim Cmd As New Data.OleDb.OleDbCommand
Dim dsAll As New Data.DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\webapp\test\web.mdb"
Cmd.Connection = Cnn
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'插入
Cmd.CommandText = "insert into main (about) values ('" + TextBox1.Text + "')"
UpdateTable()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'修改
Dim ids As Integer
ids = 1
Cmd.CommandText = "update main set about='" + TextBox1.Text + "' where id=" + ids.ToString()
UpdateTable()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'删除
Dim ids As Integer
ids = 1
Cmd.CommandText = "delete from main where id=" + ids.ToString()
UpdateTable()
End Sub
Public Sub UpdateTable()
Dim Trans As Data.OleDb.OleDbTransaction
Try
Cnn.Open()
Trans = Cnn.BeginTransaction()
Try
Cmd.Transaction = Trans
Cmd.ExecuteNonQuery()
Trans.Commit()
Catch
Trans.Rollback()
Finally
If (Cnn.State = System.Data.ConnectionState.Open) Then
Cnn.Close()
End If
End Try
Catch
'error message
End Try
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
'显示
Cmd.CommandText = "select id, about from main"
DbAdapter.SelectCommand = Cmd
DbAdapter.Fill(dsAll, "table1")
If (dsAll.Tables("table1").Rows.Count 0) Then
TextBox1.Text = dsAll.Tables("table1").Rows(0)("about")
Else
TextBox1.Text = ""
End If
End Sub
你这个问题是这样的呀:
因为你输入了10+10以后你为了结束是不是又打了个回车?那就是\n了,
但是这个\n现在被存在stdin的缓冲区里没有被取走,所以当你要输入Y或者N的时候,again将stdin的\n取走了,而没有给你输入的机会。
所以你应该是
printf("Please enter Y or N\n");
scanf("%c", again); //取走\n
scanf("%c",again); //记录Y或者N
这样就可以了。