vb.net连上了数据库,但写不进insert into 数据,急求帮忙!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dsn As String = ConfigurationSettings.AppSettings("DSN_student")
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = dsn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = conn
cmd.CommandText = "insert into Student_login (s_id,sl_name,sl_pwd,sl_phone,sl_date,sl_mailbox,sl_memo) values ('" + number.Text + "','" + realname.Text + "','" + password1.Text + "','" + phone.Text + "','" + DateTime.Now.Date + "','" + email.Text + "','" + memo.Text + "')"
Try
conn.Open()
cmd.ExecuteReader()
Panel1.Visible = False
Panel2.Visible = True
Catch
Label1.Text = "注册失败"
Finally
conn.Close()
End Try
''''''''''''''''''''''''''''''''''''''
'Dim stulab As String = DropDownList1.SelectedItem.Text
Dim zc As String = "1"
'cmd.CommandText = "update " + stulab + "_class ("
cmd.CommandText = "update stuclass set shif =" + zc + " where stu_id ='" + number.Text + "'"
Try
conn.Open()
cmd.ExecuteReader()
Label1.Text = ""
Catch ex As Exception
Label1.Text = "失败"
Finally
conn.Close()
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'重置各项textbox内容为空()
number.Text = ""
realname.Text = ""
' username.Text = ""
password1.Text = ""
password2.Text = ""
phone.Text = ""
email.Text = ""
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim bool1 As Boolean = False
' Dim dsn As String = ConfigurationSettings.AppSettings("DSN_student")
' Dim conn As New SqlClient.SqlConnection
' conn.ConnectionString = dsn
' Dim cmd As New SqlClient.SqlCommand
' cmd.Connection = conn
' If Not IsPostBack Then
' cmd.CommandText = "SELECT T_id FROM teacher_login"
' Try
' conn.Open()
' DropDownList1.DataSource = cmd.ExecuteReader
' DropDownList1.DataTextField = "T_id"
' DropDownList1.DataBind()
' bool1 = True
' Catch
' Label1.Text = "读取失败"
' Finally
' conn.Close()
' End Try
' End If
End Sub
End Class