In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how VB.NET solves the problem of DataGrid display. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
I. Program function
Upload is prohibited when the size of the uploaded image exceeds 8K or the format does not match. After the upload is passed, the uploaded picture is displayed with VB.NET DataGrid.
Second, establish a database
Create a new users table in the NorthWind database of MSSQL.
Third, form design:
1. Create a new ASP.NET Web application, name it DataGrid3, and save the path to http://192.168.0.1/DataGrid3. (note: the IP of the website on my computer is 192.168.0.1, and the home directory is D:\ web folder), and then click OK.
2. In the solution Explorer window, rename WebForm1.aspx to UpPicture.aspx, and then add a Label control and a BUtton button to the form from the toolbox. Then add a File field control form interface to the form from a HTML toolbox.
3. Right-click the project in the solution Explorer window, select add-New item-Web form, and set the name to ViewPicture.aspx. Then add a DataGrid control to the open form.
4, right-click the DataGrid control, and then click the "property Builder" below to open the "DataGrid Properties window". Click columns in the DataGrid properties window, uncheck the check box before automatically creating columns at run time, add a bound column to the selected column, enter the serial number in the header text, and enter ID in the data field. Add a bound column to the selected column, enter "avatar" in the header text, and enter headimg in the data field. Then click OK.
4. VB.NET DataGrid code design:
1 、 UpPicture.aspx
Imports System.Data.SqlClient Public Class WebForm1 Inherits System.Web.UI.Page 'form code omission' upload picture Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim img As String 'define that the postedfile file is to store the file uploaded by the user Dim postedfile As HttpPostedFile = File1.PostedFile' define a variable to store the size of the file uploaded by the user Dim intImgSize As Int32 'get the size of the file uploaded by the user IntImgSize = postedfile.ContentLength'if the file to be uploaded is not empty If intImgSize 0 Then'if it is greater than 8K, upload is prohibited If intImgSize > 8000 Then Label1.Text = "picture too big" Exit Sub End If 'define a variable to store the file type of the user's uploaded picture Dim strImgType As String = postedfile.ContentType' only accept .gif format Dim filesplit () As String = Split (strImgType "/") strImgType = filesplit (filesplit.Length-1) If strImgType "gif" Then Label1.Text = "picture format is not correct" Exit Sub End If 'entire path where the file to be uploaded is stored filesplit = Split (postedfile.FileName) "\") 'get the file name of the uploaded file Dim filename As String = filesplit (filesplit.Length-1)' Save the uploaded image to the headimg folder of the server's current directory postedfile.SaveAs (Server.MapPath ("headimg") & "\" & filename) 'define a variable to store the path to the currently uploaded picture on the server Dim imgpath As String = "headimg\" & filename img = ""' Save the picture to the database Dim scon As New SqlConnection ("server=localhost" Database=northwind;uid=sa;pwd=123 ") scon.Open () Dim scom As New SqlCommand (" insert into users values (@ img) ", scon) scom.Parameters.Add (" @ img ", SqlDbType.VarChar). Value = img Try scom.ExecuteNonQuery () Catch ex As Exception End Try scon.Close ()'go to the view picture window Response.Redirect (" ViewPicture.aspx ") End If End Sub End Class
2. ViewPicture.aspx code:
The Imports System.Data.SqlClient Public Class ViewPicture Inherits System.Web.UI.Page 'form code omits Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim scon As New SqlConnection ("server=localhost;database=northwind;uid=sa") Pwd=123 ") Dim sda As New SqlDataAdapter (" select * from users ", scon) Dim ds As New DataSet Try sda.Fill (ds) Catch ex As Exception End Try DataGrid1.DataSource = ds DataGrid1.DataBind () End Sub End Class on" how to solve the DataGrid display problem by VB.NET "ends here. I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.