vb............... help

ad.hasareli

Well-known member
  • Mar 27, 2010
    5,264
    580
    113
    දකුනේ කොල්ලෙක්
    vb.net............... help

    If sqlConn.State = ConnectionState.Closed Then
    sqlConn.Open()
    End If

    Dim code As String = cmbitemcode.Text

    Dim sqlstr As String = "Select * from items where ItemCode='" & code & "'"

    sqlAD = New SqlDataAdapter(sqlstr, sqlConn)

    Sqlds.Clear()

    sqlAD.Fill(Sqlds, "det")

    txtitemname.Text = Sqlds.Tables("det").Rows(0).Item(1)
    txtuprice.Text = Sqlds.Tables("det").Rows(0).Item(2)
    txtstoreloc.Text = Sqlds.Tables("det").Rows(0).Item(3)
    txtsupcode.Text = Sqlds.Tables("det").Rows(0).Item(4)
    txtcstock.Text = Sqlds.Tables("det").Rows(0).Item(5)


    sqlConn.Close()

    End Sub


    uda thiyena code aka me class akata set wena widihata hadala dennako plz....



    Imports System.Data.SqlClient

    Module Dbconn
    Public Dset1 As New DataSet
    Public Sqlda As New SqlDataAdapter
    Public Cmd As New SqlCommand
    Public Conn As New SqlConnection

    Public Sqlds As String = "Data Source=AMILA-03F56932B;Initial Catalog=items;Integrated Security=True"


    End Module
     
    Last edited:

    jds2012

    Well-known member
  • Mar 27, 2011
    7,945
    1,249
    113
    Everywhere...
    vcn.gif
     

    Dead Island

    Member
    Mar 22, 2012
    5,350
    682
    0
    class එකක් හදලා. ඒකේ Constructor එක use කරන්න.
    ඕන එවුන්ට බලාගන්න code එක මෙතනත් දැම්මා එහෙනම්

    if you wanna know how to retrieve data from a SQL local database with a separate class file then
    follow this example.

    '///////////////THIS IS THE MAIN FORM////////////


    Public Class Form1

    Private Sub DataBase(ByVal void)

    Dim dataBaseClassName As New Class1

    Dim receivedArray() As String = dataBaseClassName.Class1()

    txtitemname.Text = receivedArray(0)
    txtuprice.Text = receivedArray(1)
    txtstoreloc.Text = receivedArray(2)
    txtsupcode.Text = receivedArray(3)
    txtcstock.Text = receivedArray(4)

    End Sub
    End Class




    Imports System.Data.SqlClient


    '///////////THIS IS THE CLASS //////////////////

    Public Class Class1

    Public Function Class1() As String()

    Dim sqlDataSet As New DataSet("det")
    Dim Cmd As New SqlCommand

    Dim sqlConnectionString As String = "Data Source=AMILA-03F56932B;Initial Catalog=items;Integrated Security=True"
    Dim sqlCommandText As String = "Select * from items where ItemCode='" & code & "'"

    Dim sqlAdapter As New SqlDataAdapter(sqlCommandText, sqlConnectionString)
    Dim sqlConnection As New SqlConnection(sqlConnectionString)

    If (sqlConnection.State = ConnectionState.Closed) Then
    sqlConnection.Open()
    End If

    sqlDataSet.Clear()

    sqlAdapter.Fill(sqlDataSet, "det")

    sqlConnection.Close()

    Dim returnValues(4) As String

    returnValues(0) = sqlDataSet.Tables("det").Rows(0).Item(0)
    returnValues(1) = sqlDataSet.Tables("det").Rows(0).Item(1)
    returnValues(2) = sqlDataSet.Tables("det").Rows(0).Item(2)
    returnValues(3) = sqlDataSet.Tables("det").Rows(0).Item(3)
    returnValues(4) = sqlDataSet.Tables("det").Rows(0).Item(4)

    Return returnValues
    End Function

    End Class
     
    Last edited:
    • Like
    Reactions: ad.hasareli

    AheshM

    Well-known member
  • May 21, 2011
    270
    215
    63
    මොකක්ද ඔයා යූස් කරන Reference එක? Microsoft ActiveX Data Objects 2.7 ද?
    මට ඔයා කියපු එක ඒ තරම්ම තේරුනේ නෑ. ඒත් ෆෝම් එකක හදපු කනෙක්ෂන් එකක් Module එකකට ගන්නනම් ඒකෙ තියෙන Variable ඔක්කොම Public Variable වලට වෙනස් කරන්න ඕන. තව හදපු Function හෙම තියේ නම් ඒවත් Public කරන්න ඕන. ඊට පස්සෙ අර කෝඩිං ටිකම පේස්ට් කරන්න.

    Eg:
    1. Public Fuction <Name>
    <Code>
    End Function

    2. Public x as string
     

    ad.hasareli

    Well-known member
  • Mar 27, 2010
    5,264
    580
    113
    දකුනේ කොල්ලෙක්
    If sqlConn.State = ConnectionState.Closed Then
    sqlConn.Open()
    End If

    Dim code As String = cmbitemcode.Text

    Dim sqlstr As String = "Select * from items where ItemCode='" & code & "'"

    sqlAD = New SqlDataAdapter(sqlstr, sqlConn)

    Sqlds.Clear()

    sqlAD.Fill(Sqlds, "det")

    txtitemname.Text = Sqlds.Tables("det").Rows(0).Item(1)
    txtuprice.Text = Sqlds.Tables("det").Rows(0).Item(2)
    txtstoreloc.Text = Sqlds.Tables("det").Rows(0).Item(3)
    txtsupcode.Text = Sqlds.Tables("det").Rows(0).Item(4)
    txtcstock.Text = Sqlds.Tables("det").Rows(0).Item(5)


    sqlConn.Close()

    End Sub


    uda thiyena code aka me class akata set wena widihata hadala dennako plzzzz.



    Imports System.Data.SqlClient

    Module Dbconn
    Public Dset1 As New DataSet
    Public Sqlda As New SqlDataAdapter
    Public Cmd As New SqlCommand
    Public Conn As New SqlConnection

    Public Sqlds As String = "Data Source=AMILA-03F56932B;Initial Catalog=items;Integrated Security=True"


    End Module