今天尝试了一下用SQL存储过程写程序 ,把我的一些心得体会写在这里。
其实我对于存储过程如何写,怎么 在程序中调用已经渴望很久了,今天终于抽时间捣鼓了一阵并且达到了我的预期目的,以下是我的代码部分:
存储过程代码:
ALTER PROCEDURE dbo.AddType
@FatherType nchar(20),
@SonType nchar(20)
AS
insert into viewtype(TnameOne,TnameTwo) values(@FatherType,@SonType)
RETURN
要特别注意其中的红色数字部分,因为没有这个(20)默认情况下是1只能将字符串的第一个字符写入到数据库中,我刚开始的时候就是没有注意这个细节!特此提示一下!
程序代码:
SqlDatabase DB = new SqlDatabase();
DB.DbConn.Open();
DB.DbCmd.CommandText = "Addtype";
DB.DbCmd.CommandType = CommandType.StoredProcedure;
DB.DbCmd.Parameters.Add ("@fatherType",TxtFtype.Text );
DB.DbCmd.Parameters.Add ("@sonType",TxtZtype.Text );
//DB.DbCmd.CommandText = "insert into viewtype(TnameOne,TnameTwo) values('" + TxtFtype.Text + "','"+ TxtZtype.Text +"')";
DB.DbCmd.ExecuteNonQuery();
DB.DbConn.Close();
DB.DbCmd.Dispose();
DB.DbConn.Dispose()
其实我对于存储过程如何写,怎么 在程序中调用已经渴望很久了,今天终于抽时间捣鼓了一阵并且达到了我的预期目的,以下是我的代码部分:
存储过程代码:
ALTER PROCEDURE dbo.AddType
@FatherType nchar(20),
@SonType nchar(20)
AS
insert into viewtype(TnameOne,TnameTwo) values(@FatherType,@SonType)
RETURN
要特别注意其中的红色数字部分,因为没有这个(20)默认情况下是1只能将字符串的第一个字符写入到数据库中,我刚开始的时候就是没有注意这个细节!特此提示一下!
程序代码:
SqlDatabase DB = new SqlDatabase();
DB.DbConn.Open();
DB.DbCmd.CommandText = "Addtype";
DB.DbCmd.CommandType = CommandType.StoredProcedure;
DB.DbCmd.Parameters.Add ("@fatherType",TxtFtype.Text );
DB.DbCmd.Parameters.Add ("@sonType",TxtZtype.Text );
//DB.DbCmd.CommandText = "insert into viewtype(TnameOne,TnameTwo) values('" + TxtFtype.Text + "','"+ TxtZtype.Text +"')";
DB.DbCmd.ExecuteNonQuery();
DB.DbConn.Close();
DB.DbCmd.Dispose();
DB.DbConn.Dispose()
浙公网安备 33010602011771号