Protected Sub Btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Add.Click
If Trim(txt_A_memberID.Text) = "" Then
lbl_A_memberID.Visible = True
txt_A_memberID.Focus()
Return
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand()
cmd.CommandText = "INSERT INTO Table_บุคลากร(A_memberID,A_membernameL,A_Agency,A_memberTel,A_Date,A_FileName)" & _
" VALUES(@A_memberID,@A_membernameL,@A_Agency,@A_memberTel,@A_Date,@A_FileName) "
cmd.Parameters.Add("@A_memberID", SqlDbType.VarChar).Value = txt_A_memberID.Text
cmd.Parameters.Add("@A_membernameL", SqlDbType.VarChar).Value = txt_A_membernameL.Text
cmd.Parameters.Add("@A_Agency", SqlDbType.VarChar).Value = txt_A_memberAgency.Text
cmd.Parameters.Add("@A_memberTel", SqlDbType.VarChar).Value = txt_A_memberTel.Text
cmd.Parameters.Add("@A_Date", SqlDbType.DateTime).Value = DateTime.Now
Response.Redirect("ข้อมูลบุคลากร.aspx")
If Me.FileUpload1.HasFile Then
Me.FileUpload1.SaveAs(Server.MapPath("Picture/" & FileUpload1.FileName))
cmd.Parameters.Add("@A_FileName", SqlDbType.VarChar).Value = "Picture/" & FileUpload1.PostedFile.FileName
End If
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
GetData()
End Sub
Tag : ASP.NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET