#vb.net
#vb.net
Вопрос:
Я сохранил таблицу посещаемости имени процедуры
ALTER proc [dbo].[Attendancesheet] (@trainid nvarchar (max))
as
begin
declare @DyPQ as nvarchar (max)
declare @CN as nvarchar(max)
select @CN =ISNULL(@CN ',','')
QUOTENAME(lecturename)
FROM (SELECT DISTINCT lecturename FROM ATT where trainid=@trainid) as Lectures
--Print @CN
SET @DyPQ= N'
select * from
(
select (select trinsname from trains where trinsid=e.trinsid) as [TrainerNmae],
lecturename,
att_status
from att e where (trainid=@trainid))as p
pivot
(
max(Att_status) for lecturename in(' @CN '))as f'
execute (@DyPQ);
end
Я хочу передать параметр @trainid из vb.net 2010 combobox значение
vb.net код — это:
Dim connect As New Connection
connect.getconnection()
Dim cmd As New SqlCommand("AttendanceSheet", connect.conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "AttendanceSheet"
' ---------------------- define parameter to stored procedure
Dim trainid As SqlParameter = cmd.Parameters.Add("@trainid", SqlDbType.NVarChar)
trainid.Direction = ParameterDirection.Input
trainid.Value = Me.cbotrainings.SelectedValue.ToString
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader())
connect.conn.Close()
Me.dg1.DataSource = dt
Комментарии:
1. Вы пробовали это ‘Dim trainid как SqlParameter = cmd.Parameters.Add(«@trainid», SqlDbType.NVarChar)’ без ‘@’ в имени параметра?
Ответ №1:
Вы можете попробовать этот код :
Dim trainid As SqlParameter = cmd.Parameters.AddWithValue("@trainid", Me.cbotrainings.SelectedValue.ToString().Trim)