Вызов метода пользовательских элементов управления из другой формы
I want to call method from Usercontrol in form the method(showlistbox) is to fill the products in listbox, when the user update or delete a product I want to call the method so it will update the listbox that contains the product in the usercontrol. I have 2 forms main form that have 'usercontrol' the 'usercontrol' have listbox and other controls, I'm using method called 'showlistbox' display the products in the listbox, if the user double click on any product in listbox this will open new form contains the product details, so if the user delete or update the product i want the listbox in the 'usercontrol' also update or refresh by calling the ' showlistbox' method. i tried this but it show me this error : the connectionstring property has not been initialized this is the code:
Что я уже пробовал:
dim m_product as new products m_product.showlistbox() And this is the showlistbox method: Public Sub showlistbox() Try 'فحص الاتصال بقاعدة البيانات If SQL.conn.State = ConnectionState.Open Then SQL.conn.Close() End If SQL.conn.Open() Dim dt As New DataTable Dim ds As New DataSet ds.Tables.Add(dt) Dim da As New SqlDataAdapter("select pname from products where not esection= N'archive' order by date DESC", SQL.conn) da.Fill(dt) Dim myRow As DataRow For Each myRow In dt.Rows ListBox1.Items.Add(myRow.Item(0)).ToString() Next SQL.conn.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub but its not working, how can i done it?
FranzBe
Вы должны убедиться в этом перед вызовом SQL.conn.Open() должна быть оценка строки подключения к объекту SqlConnection, что-то вроде этого:
Отдельный Конн как объект sqlconnection
conn = New SqlConnection ("yourConnectionString")
Rabee Qabaha
у меня есть класс для подключения, мне не нужно добавлять соединение более одного раза