Dim rS As New ADODB.Recordset
Dim cn_str As String
Dim sql_str As String
cn_str = "Driver={SQL Server};Server=zcj;UID=Sa;PWD=sa;Database=Student"
cn.Open cn_str
Dim cmd As New Command
Dim p1 As Parameter, p2 As Parameter, p3 As Parameter
Dim sql_str As String
cmd.CommandType = adCmdText
Set cmd.ActiveConnection = cn
sql_str = "INSERT INTO result_info VALUES(?,?,?)"
cmd.CommandText = sql_str
Set p1 = cmd.CreateParameter("p1", adInteger, adParamInput)
Set p2 = cmd.CreateParameter("p2", adChar, adParamInput, 3)
Set p3 = cmd.CreateParameter("p3", adInteger, adParamInput)
cmd.Parameters.Append p1
cmd.Parameters.Append p2
cmd.Parameters.Append p3
p1.Value = Combo1.Text
p2.Value = Combo2.Text
If Text1.Text <> "" Then
p3.Value = Text1.Text '指定成绩
cmd.Execute
MsgBox "数据已经存盘!", vbOKOnly + vbInformation, Me.Caption
Else
MsgBox "请输入一个成绩。", vbOKOnly + vbInformation, Me.Caption
Exit Sub
End If
VB中构造sql语句
sqlstr = "SELECT RTRIM(course_name)+':'+CONVERT(VARCHAR(6),result) AS kr"
sqlstr = sqlstr & vbCrLf & "FROM student_info, result_info,course_info"
sqlstr = sqlstr & vbCrLf & "where student_info.student_id= result_info. student_id "
sqlstr = sqlstr & vbCrLf & "AND result_info.course_no= course_info. course_no "
sqlstr = sqlstr & vbCrLf & "AND student_name='" & DataList1.Text & "'"