用asp.net 和存储过程操作时:
sql server:
CREATE PROC GetUserName
@UserId INT,
@UserName NVARCHAR(20) OUTPUT -- 要输出的参数
AS
BEGIN
-- 将uName的值赋给 @ostrUserName 变量,即要输出的参数
SELECT @UserName=UserName FROM admin WHERE ID=@UserId
END
GOasp.net代码:
Dim str As String = "server=localhost;database=newdb;"
Dim con As sqlConnection = New sqlConnection(str)
dim sql as string
sub page_load(sender as object,e as eventargs)
'if not ispostback then
con.open() '出现错误为:SQL Server does not exist or access denied.
dim loadcommand as sqlcommand=new sqlcommand("GetUserName",con)
loadcommand.commandtype=commandtype.storedprocedure
loadcommand.parameters.add(new sqlparameter("@UserId",sqldbtype.int,4)) loadcommand.parameters("@UserId").value=13
loadcommand.executenonquery() con.close()
response.Write(loadcommand.parameters("@UserName").value)
' end if
end sub
sql server:
CREATE PROC GetUserName
@UserId INT,
@UserName NVARCHAR(20) OUTPUT -- 要输出的参数
AS
BEGIN
-- 将uName的值赋给 @ostrUserName 变量,即要输出的参数
SELECT @UserName=UserName FROM admin WHERE ID=@UserId
END
GOasp.net代码:
Dim str As String = "server=localhost;database=newdb;"
Dim con As sqlConnection = New sqlConnection(str)
dim sql as string
sub page_load(sender as object,e as eventargs)
'if not ispostback then
con.open() '出现错误为:SQL Server does not exist or access denied.
dim loadcommand as sqlcommand=new sqlcommand("GetUserName",con)
loadcommand.commandtype=commandtype.storedprocedure
loadcommand.parameters.add(new sqlparameter("@UserId",sqldbtype.int,4)) loadcommand.parameters("@UserId").value=13
loadcommand.executenonquery() con.close()
response.Write(loadcommand.parameters("@UserName").value)
' end if
end sub
出现错误为 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
怎么解决啊 急等....
你的sa密码是否不对,可以在企业管理器里进行修改
密码不对