求助 谢谢谢谢谢谢谢谢
我编了一个学生成绩录入程序但有错误,不会修改,请帮帮忙Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student " _
& "where student.id="id"") 错误提示:应为")"
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("id"','"&name&"','"&age&"','"&grade&"')"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id".conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id='"&id&"'",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='" _
id"'and stumark.c_id=(select c_id from course where course='"&course&") _
错误提示:应为语句结束
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
--------------------编程问答--------------------
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student " _
& "where student.id="&id&"") '错误提示:应为")"
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("&id&",'"&name&"','"&age&"','"&grade&"')"),conn) '错误提示:应为逗号、“)”或有效的表达式继续符
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader '错误提示:"conn"不是"string"的成员
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(id)from student where id='"&id&"'",conn)
Dim dr As OleDb.OleDbDataReader '错误提示:应为逗号、“)”或有效的表达式继续符
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='"&id&"'and stumark.c_id=(select c_id from course where course='"&course&"') '错误提示:应为语句结束
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
试试 --------------------编程问答-------------------- 还不行,就加我QQ:280820560 --------------------编程问答-------------------- 我编了一个学生成绩录入程序但有错误,不会修改,请帮帮忙
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student " _
& "where student.id="id)
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("'"id"','"&name&"','"&age&"','"&grade&"')"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id=" '"&id&"',conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = "select mark from stumark,student where stumark.id=student.id and student.id="& '"id"' "and stumark.c_id=(select c_id from course where course='"&course&")";
错误提示:应为语句结束
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
--------------------编程问答-------------------- 这么一大片下来错误好多.
首先 "&grade&" 不应该这样写,应该是 " & grade & " , 应该给连接符两边留个空格
其他的楼上的大侠们已经提到了.
给另外一个写入方法给你,自己慢慢改也可以了.
Try
Dim acc As String
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\kssi.mdb;Persist Security Info=False")
acc = "INSERT INTO inku (商品大类,商品名称,商品规格,商品单位,商品编码,入库数量,单价,供应商,入库人,仓库名称,入库日期,商品备注,商品图片,附加信息) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim cmd As New OleDbCommand(acc, conn)
Dim pc As OleDbParameterCollection = cmd.Parameters
With pc
.Add("商品大类", OleDbType.VarChar)
.Add("商品名称", OleDbType.VarChar)
.Add("商品规格", OleDbType.VarChar)
.Add("商品单位", OleDbType.VarChar)
.Add("商品编码", OleDbType.VarChar)
.Add("入库数量", OleDbType.Integer)
.Add("单价", OleDbType.Integer)
.Add("供应商", OleDbType.VarChar)
.Add("入库人", OleDbType.VarChar)
.Add("仓库名称", OleDbType.VarChar)
.Add("入库日期", OleDbType.Date)
.Add("商品备注", OleDbType.VarChar)
.Add("商品图片", OleDbType.VarChar)
.Add("附加信息", OleDbType.LongVarChar)
End With
pc("商品大类").Value = fin1
pc("商品名称").Value = fin2
pc("商品规格").Value = fin3
pc("商品单位").Value = fin4
pc("商品编码").Value = fin5
pc("入库数量").Value = fin6
pc("单价").Value = fin7
pc("供应商").Value = fin8
pc("入库人").Value = fin9
pc("仓库名称").Value = fin10
pc("入库日期").Value = fin11
pc("商品备注").Value = fin12
pc("商品图片").Value = fin13
pc("附加信息").Value = fin14
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MsgBox("在写入 新商品(入库) 数据时发生错误" & vbCr & "错误原因: " & ex.Message & vbCr & "请查看您的商品记录里有没有您添加的商品记录,没有的话请重新添加。")
End Try
这是偶的商管软件的一段写入数据库的代码,LZ 可以参考下. --------------------编程问答--------------------
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student where student.id='" & id &"'") 错误提示:应为")"
>注意传参数的引号,字符串用'
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("'" & id & "','" & name & "','" & age & "','" & grade & "'"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
>注意传参数的引号,字符串用'
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
>是, 不是.
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id='" & id & "'",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
>字符串连接时要用空格表示
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='" _
id"'and stumark.c_id=(select c_id from course where course='"&course&") _
错误提示:应为语句结束
>"select stumark.mark from stumark inner join student on stumark.id=student.id and student.id='" & _
id "' inner join course on student.id=course.c_id where student.id='" & id & "' and course.c_id='" & course & "'")
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
你要注意字符串连接时的格式.
SQL传参数的时候的格式.
最后一句SQL不知道你要表示什么样的内容.
结合有多种结果,是不是你想要的结果,如果不是 那就把你想要的结果说一下.
我们可以帮你参考... --------------------编程问答-------------------- 上面的看起来比较麻烦
我从新给你发
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student where student.id='" & id &"'") 错误提示:应为")"
>注意传参数的引号,字符串用'
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("'" & id & "','" & name & "','" & age & "','" & grade & "'"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
>注意传参数的引号,字符串用'
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
>是, 不是.
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id='" & id & "'",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
>字符串连接时要用空格表示
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='" _
id"'and stumark.c_id=(select c_id from course where course='"&course&") _
错误提示:应为语句结束
>"select stumark.mark from stumark inner join student on stumark.id=student.id and student.id='" & _
id "' inner join course on student.id=course.c_id where student.id='" & id & "' and course.c_id='" & course & "'")
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
你要注意字符串连接时的格式.
SQL传参数的时候的格式.
最后一句SQL不知道你要表示什么样的内容.
结合有多种结果,是不是你想要的结果,如果不是 那就把你想要的结果说一下.
我们可以帮你参考... --------------------编程问答-------------------- Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student where student.id='" & id &"'") 错误提示:应为")"
>注意传参数的引号,字符串用'
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values("'" & id & "','" & name & "','" & age & "','" & grade & "'"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
>注意传参数的引号,字符串用'
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
>是, 不是.
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id='" & id & "'",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
>字符串连接时要用空格表示
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='" _
id"'and stumark.c_id=(select c_id from course where course='"&course&") _
错误提示:应为语句结束
>"select stumark.mark from stumark inner join student on stumark.id=student.id and student.id='" & _
id "' inner join course on student.id=course.c_id where student.id='" & id & "' and course.c_id='" & course & "'")
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
你要注意字符串连接时的格式.
SQL传参数的时候的格式.
最后一句SQL不知道你要表示什么样的内容.
结合有多种结果,是不是你想要的结果,如果不是 那就把你想要的结果说一下.
我们可以帮你参考... --------------------编程问答-------------------- 下面代码可以不:
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id, name, age, grade As String
Dim count As Integer
id = Trim(TextBox1.Text)
name = Trim(TextBox2.Text)
grade = Trim(TextBox3.Text)
age = Trim(TextBox4.Text)
If id = "" Then
MessageBox.Show("学号不能为空")
Return
End If
Dim com As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader ' cmd.CommandText = _
' "SELECT * FROM Titles JOIN Publishers " _
' & "ON Publishers.PubId = Titles.PubID " _
' & "WHERE Publishers.State = 'CA'"
com = New OleDb.OleDbCommand
Dim conn As New OleDb.OleDbConnection
com.CommandText = _
("select count * from student "_
& "where student.id='"+id+"'") 错误提示:应为")"
com.Connection = Conn
Conn.open()
dr = com.ExecuteReader
dr.Read()
count = dr.GetValue(0)
dr.Close()
If count <> 0 Then
MessageBox.Show("学号重复!请确认")
Else
com=new OleDb.OleDbCommand ("insert into student(id,name,age,grade)values('"+id+"','"+name+"','"+age+"','"+grade+"')"),conn) 错误提示:应为逗号、“)”或有效的表达式继续符
End If
com.Dispose()
conn.close()
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand("select course from course order by c_id",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:"conn"不是"string"的成员
Dim course As String
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
Dim id As String
Dim count As Integer
id = Trim(TextBox1.Text)
Dim com As New OleDb.OleDbCommand
dim com as New OleDb.OleDbCommand("select count(*)from student where id='"+id+"'",conn)
Dim dr As OleDb.OleDbDataReader 错误提示:应为逗号、“)”或有效的表达式继续符
End If
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
End Class
Public Class Form5
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim id, course As String
id = Trim(TextBox1.Text)
course = Trim(ComboBox1.SelectedItem)
If id = "" Then
MessageBox.Show("请输入学号!")
Return
End If
If course = "" Then
MessageBox.Show("请选择课程!")
Return
End If
Dim com As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim conn As New OleDb.OleDbConnection
com.Connection = conn
com.CommandText = _
"select mark from stumark,student where stumark.id=student.id and student.id='" _
id"'and stumark.c_id=("select c_id from course where course='"+course+"'") _
错误提示:应为语句结束
conn.open()
dr = com.ExecuteReader
dr.Read()
TextBox4.Text = Trim(dr.GetString(0))
dr.Close()
com.Dispose()
conn.close()
Button1.Enabled = True
End Sub
--------------------编程问答-------------------- 这么多,看的我头晕!!
补充:.NET技术 , VB.NET