Results 1 to 3 of 3

Thread: MSSQL 2000 DB Editing

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    MSSQL 2000 DB Editing

    Can someone give me example how to edit and view information from MSSQL 2000 database in text fields

    Example i have this info:

    First i need to display all accounts in a combobox that are in table MEMB_INFO
    when i select the combobox to drop down all accounts
    if i want to write a account name in the combobox to show it in the combobox as searched

    Username: textbox
    Password: textbox2

    Character: textbox3
    and etc..
    something like this
    Save button

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: MSSQL 2000 DB Editing

    First i wanted to do config Form1, where to write information about the database connection, but i dont know how to make it when he selects in Database from the combobox to open form2 where he will read tables information

    Code:
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Linq
    Imports System.Text
    Imports System.Windows.Forms
    
    Imports System.Data.SqlClient
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub BtnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click
            Dim conn As SqlConnection
            Dim command As SqlCommand
            Dim reader As SqlDataReader
            Dim sql As String = ""
            Dim ConnectionString As String = ""
    
            Try
                ConnectionString = (("Data Source =" + txtDataSource.Text & "; User ID=") + txtUserID.Text & "; Password=") + txtPassword.Text & ""
                conn = New SqlConnection(ConnectionString)
                conn.Open()
                sql = "EXEC sp_databases"
                'sql = "SELECT * FROM sys.databases d WHERE d.database_id>4";
                command = New SqlCommand(sql, conn)
                reader = command.ExecuteReader()
                cmbDatabases.Items.Clear()
                While reader.Read()
                    cmbDatabases.Items.Add(reader(0).ToString())
                End While
                reader.Dispose()
                conn.Close()
                conn.Dispose()
    
                txtDataSource.Enabled = False
                txtPassword.Enabled = False
                txtUserID.Enabled = False
                BtnConnect.Enabled = False
                BtnDisconnect.Enabled = True
                cmbDatabases.Enabled = True
    
    
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    
        Private Sub BtnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisconnect.Click
            txtDataSource.Enabled = True
            txtUserID.Enabled = True
            txtPassword.Enabled = True
            cmbDatabases.Enabled = False
            BtnConnect.Enabled = True
            
        End Sub
    
        Private Sub cmbDatabases_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDatabases.SelectedIndexChanged
            If cmbDatabases.SelectedItem = True Then
                Form2.Show()
                Me.Close()
            End If
        End Sub
    End Class
    My idea is to create the form1 to be config and when they put the config to open form2 and to read in Form2 the information about the database that they writed in Form1
    Last edited by diablo21; Jun 22nd, 2014 at 07:20 AM.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: MSSQL 2000 DB Editing

    You're throwing a whole lot of questions into one here. Your first problem is that you want the user to enter the connection parameters and then connect to the database they specify, correct? If so then I suggest that you use a SqlConnectionStringBuilder to build your connection string in a neater, less error-prone manner. You should create a SqlConnectionStringBuilder, set its properties with the data entered by the user, create a SqlConnection with the connection string from the SqlConnectionStringBuilder and then try to open the connection. You might follow the CodeBank link in my signature below and check out my Protected Configuration thread for an example. It does more than you need but you can just ignore the extra stuff.

    Until you can do that, don't worry about anything else. By concentrating on one task at a time, you help to avoid confusion and also ensure that, if something doesn't work, you know pretty where the issue is. If you're trying to get a number of things to work all at the same time and you don't get the desired result then you don't know what part the issue is in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width