ник: Едрёныч
создал хранимую процедуру для выборки Фамилии покупателя в зависимости от CustomerID
в базе Northwind
ALTER PROCEDURE sp_ContactName
@CustomerID nchar
AS
SELECT Customers.ContactName, Customers.CompanyName, Orders.CustomerID
FROM Customers INNER JOIN
Orders ON Customers.CustomerID = Orders.CustomerID
WHERE (Orders.CustomerID = @CustomerID)
/* SET NOCOUNT ON */
RETURN
написал на форме код
комбобокса:
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlConnectionStringBuilder
Public Class Form3
'загружаю данные в Combobox1
Public Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn3 As New SqlConnectionStringBuilder()
Dim strSQL3 As String
'strConn3 = "Data Source=.\SQLExpress;Initial Catalog=Northwind;Integrated Security=True;"
strConn3.DataSource = ".\SQLExpress"
strConn3.InitialCatalog = "Northwind"
strConn3.IntegratedSecurity = True
Using cn3 As New SqlConnection(strConn3.ConnectionString)
cn3.Open()
strSQL3 = "SELECT DISTINCT CustomerID FROM Orders"
Dim da3 As New SqlDataAdapter(strSQL3, cn3)
Dim ds3 As New DataSet()
da3.Fill(ds3, "Orders")
With ds3
Me.ComboBox1.DataSource = .Tables("Orders")
Me.ComboBox1.DisplayMember = "CustomerID"
End With
End Using
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' пытаюсь изменить значения в DATAGRIDVIEW1
Dim strConn4 As New SqlConnectionStringBuilder()
strConn4.DataSource = ".\SQLExpress"
strConn4.InitialCatalog = "Northwind"
strConn4.IntegratedSecurity = True
Using cn4 As New SqlConnection(strConn4.ConnectionString)
cn4.Open()
Dim cmd As New SqlCommand("sp_ContactName", cn4)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue(@CustomerID,SqlDbType.NChar)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "Customers")
DataGridView1.DataBindings.Add("", (ds), "Customers")
DataGridView1.DataMember = "Customers"
DataGridView1.DataSource = ds
cn4.Close()
End Using
End Sub
End Class
подскажите что упустил, где ошибка?
понимаю, что надо привязать данные к Datagridview, но как это правильно сделать не знаю