陈恩点vb.net的简单介绍

VS2010用VB语言实现数据库连接,并将表中的数据显示在GridView上。

'================================ACCESS=================================  

创新互联长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为乳源企业提供专业的成都网站设计、做网站,乳源网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制开发。

Public AccessConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"  _

"Data Source=D:\Simple.mdb;"  _

"Persist Security Info=False" 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Try

Dim AccessString As String = "SELECT * FROM 示例表 "

Dim AccessConn As New OleDb.OleDbConnection(AccessConnectionString)

AccessConn.Open()

Dim AccessAdapter As OleDbDataAdapter = New OleDbDataAdapter(AccessString, AccessConn)

'有返回值

Dim TempDataSet As New DataSet

AccessAdapter.Fill(TempDataSet)

DataGridView1.DataSource = TempDataSet.Tables(0)

AccessConn.Close()

Catch AccessException As Exception

MsgBox(AccessException.Message)

End Try

End Sub

陈恩点原创,转载请保留!

'================================SQL================================

Protected Const SqlConnectionString As String = _

"Server=CED-PC\SQLEXPRESS;"  _

"DataBase=;"  _

"Integrated Security=SSPI"

#Region "Display data"

' Handles the click event for the Display button. This handler gets the product

' information from the Contact table puts it into a DataSet which is used to

' bind to a DataGrid for display. Custom style objects are used to give the 

' DataGrid a nice appearance.

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

If IsNothing(DataGridView1.DataSource) Then

Dim strSQL As String = _

"USE Simple"  vbCrLf  _

"SELECT * "  _

"FROM GetContacts"

Try

' The SqlConnection class allows you to communicate with SQL Server.

' The constructor accepts a connection string as an argument.  This

' connection string uses Integrated Security, which means that you 

' must have a login in SQL Server, or be part of the Administrators

' group for this to work.

Dim dbConnection As New SqlConnection(connectionString)

' A SqlCommand object is used to execute the SQL commands.

Dim cmd As New SqlCommand(strSQL, dbConnection)

' The SqlDataAdapter is responsible for using a SqlCommand object to 

' fill a DataSet.

Dim da As New SqlDataAdapter(cmd)

Dim dsContacts As New DataSet()

da.Fill(dsContacts, "Contact")

With Me.DataGridView1

.Visible = True

.AutoGenerateColumns = False

.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender

.BackColor = Color.WhiteSmoke

.ForeColor = Color.MidnightBlue

.CellBorderStyle = DataGridViewCellBorderStyle.None

.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 8.0!, FontStyle.Bold)

.ColumnHeadersDefaultCellStyle.BackColor = Color.MidnightBlue

.ColumnHeadersDefaultCellStyle.ForeColor = Color.WhiteSmoke

.DefaultCellStyle.ForeColor = Color.MidnightBlue

.DefaultCellStyle.BackColor = Color.WhiteSmoke

End With

Me.DataGridView1.DataSource = dsContacts.Tables(0)

Dim newColumn As Integer = Me.DataGridView1.Columns.Add("ContactID", "Contact ID")

Me.DataGridView1.Columns(newColumn).DataPropertyName = "ContactID"

newColumn = Me.DataGridView1.Columns.Add("FirstName", "First Name")

Me.DataGridView1.Columns(newColumn).DataPropertyName = "FirstName"

newColumn = Me.DataGridView1.Columns.Add("LastName", "Last Name")

Me.DataGridView1.Columns(newColumn).DataPropertyName = "LastName"

Catch sqlExc As SqlException

MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End If

End Sub

#End Region

陈恩点原创,转载请保留!

vb.net如何实现运行时改变控件的大小?

陈恩点在此为你解答如有错误请见谅:

思路是这样的:

先判断鼠标位置(MouseMove事件)

如果在边缘,同时鼠标左键是按下的

窗体增加 增加数为鼠标移动数

各位大神帮个忙做个vb.net的程序吧,,,下面是程序要求,一个关于坦克游戏的

陈恩点在此为你解答如有错误请见谅:

好复杂的 这个编程有一定难度啊

有没有报酬啊

vb.net中listbox内容自动换行如何实现

也不是不可以实现,只不过复杂一点而已,具体看下面代码。不过在需要换行等情况下的文本显示,还是建议用RichTextBox开启只读属性比较省心、比较合适。

Private Sub AutoNextRow()

'获取ListBox行集合文本

Dim length As Integer = (ListBox1.Items.Count - 1)

Dim items(length) As String '行文本数组

For i As Integer = 0 To length

items(i) = ListBox1.Items(i).ToString

Next

'处理ListBox换行

ListBox1.Items.Clear() '清空行内容

Using g As Graphics = Graphics.FromHwnd(ListBox1.Handle)

Dim result As New List(Of Object)

Dim w As Single = ListBox1.ClientSize.Width

Dim sf As SizeF, str As StringBuilder

For Each s As String In items

str = New StringBuilder

For i As Integer = 0 To (s.Length - 1)

sf = g.MeasureString(str.ToString  s(i), ListBox1.Font) 

If sf.Width  w Then

result.Add(str.ToString)

str = New StringBuilder

End If

str.Append(s(i))

If i = s.Length - 1 Then result.Add(str.ToString)

Next

Next

ListBox1.Items.AddRange(result.ToArray) '填充行内容

End Using

End Sub

文章标题:陈恩点vb.net的简单介绍
当前链接:https://www.cdcxhl.com/article4/hhgoie.html

成都网站建设公司_创新互联,为您提供搜索引擎优化自适应网站用户体验标签优化品牌网站设计App开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

商城网站建设