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

被折叠的 条评论
为什么被折叠?



