博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
asp.net 操作存储过程
阅读量:6979 次
发布时间:2019-06-27

本文共 1078 字,大约阅读时间需要 3 分钟。

 

 

 
protected 
void Button1_Click(
object sender, EventArgs e)
    {
        
string getNewsTitle = 
this.TextBox1.Text.ToString().Trim();
        
string getNewsContent = 
this.TextBox2.Text.ToString();
        
string getNewsAuthor = 
this.TextBox3.Text.ToString();
        
string strConn = WebConfigurationManager.ConnectionStrings[
"
SteelFactoryConnectionString
"].ConnectionString;
        SqlConnection myConn = 
new SqlConnection(strConn);
        SqlCommand mycomm = 
new SqlCommand(
"
sp_AddNews
",myConn);
        mycomm.CommandType = CommandType.StoredProcedure;
        
#region 为 3个参数指定数据类型并赋值
        SqlParameter[] paras = 
        {
            
new SqlParameter(
"
@sNewsTitle
",SqlDbType.NVarChar,
100),
            
new SqlParameter(
"
@sNewsContent
", SqlDbType.NText),
            
new SqlParameter(
"
@sNewsAuthor
", SqlDbType.NVarChar, 
50),
                    
        };
        paras[
0].Value = getNewsTitle;
        paras[
1].Value = getNewsContent;
        paras[
2].Value = getNewsAuthor;
       
        
foreach (SqlParameter pa 
in paras)
        {
            mycomm.Parameters.Add(pa);
        }
        myConn.Open();
        
try
        {
            mycomm.ExecuteNonQuery();
        }
        
catch
        {
            
this.Label1.Text = 
"
操作遇到不可知错误!请与管理员联系
";
        }
        
#endregion
    }

 

转载于:https://www.cnblogs.com/tiger8000/archive/2011/10/08/2201803.html

你可能感兴趣的文章
UITextField的代理方法
查看>>
无人驾驶相关数据集
查看>>
C 的大致运行原理。
查看>>
关于jsp和eclipse服务器端的相关配置和JS的区别
查看>>
JavaScript - 数据类型和变量
查看>>
TCP/IP:IP选项处理
查看>>
【网摘】检测 iframe 是否加载完成
查看>>
cocos2dx 3.x(动态改变精灵的背景图片)
查看>>
cocos2d-x JS 获取当前系统时间(解决屏幕双击点击事件)
查看>>
支付宝接入参考博客
查看>>
学习Spring中遇到关于BeanFactory及测试类的问题
查看>>
现实迷途 第七章 特殊客户
查看>>
找水王
查看>>
fgets()用法笔记
查看>>
mysql以及mysql bench安装教程
查看>>
Linear Regression with machine learning methods
查看>>
在 Azure 网站上使用 Memcached 改进 WordPress
查看>>
数据库备份定期删除程序的开发。
查看>>
启动Genymotion时报错Failed to initialize backend EGL display
查看>>
BZOJ 1040 ZJOI2008 骑士 树形DP
查看>>