帮助ConnectionString [英] help with ConnectionString

查看:66
本文介绍了帮助ConnectionString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小型数据库,我希望显示有关学生的所有信息,用户

输入他的学生证我知道有一些误解,但希望有人生病帮助我通过这个我的拳头项目



我使用visual studio 2008照顾我的数据库



screenshot



我认为此声明有错误


I create small database and I want to show all information about the students that user
enter his Students ID I know that has some misktake but hope someone ill get help me to get trough this as its my fist project

I caret my database using visual studio 2008

screenshot

I think there is mistake at this statement

cnn.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"





和另一个正在调用的人尝试更改所有(*)字段以选择我的数据库的一列但是它仍然提供我数据库中的所有数据





and the other one at way of calling tried to change all (*) fields to select one column of my database but it still give all the data in my database

cmd.CommandText = "select * from Table1"







<pre lang="vb">Public Class Form1

    Dim cnn As OleDb.OleDbConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1DataSet2.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter1.Fill(Me.Database1DataSet2.Table1)
        'TODO: This line of code loads data into the 'Database1DataSet1.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.Database1DataSet1.Table1)
        cnn = New OleDb.OleDbConnection
        cnn.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim cmd As OleDb.OleDbCommand

        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If
        cmd.Connection = cnn
        cmd.CommandText = "select * from Table1"
        cmd.ExecuteNonQuery()

    End Sub
End Class

推荐答案

您可以使用以下代码填充数据网格

You can use the code bellow to populate the data grid
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim constr as new OleDb.OleDbConnection
constr.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"
Dim sqlstr as string=""
sqlstr="select * from Table1 where StudentID=" & Textbox1.text

       Try
            Dim ds As New DataSet
            Dim apt As New SqlDataAdapter
            apt.Dispose()
            ds.Dispose()
            apt = New SqlDataAdapter(sqlstr, constr)
            apt.Fill(ds)
            Datagridview1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try 
End Sub


这篇关于帮助ConnectionString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆