zoukankan      html  css  js  c++  java
  • C#与sql server数据库存储过程的操作实例

    通过这几天的学习和实际操作,把C#与sql server数据库存储过程的操作搞清楚了。

     1 using System;
     2 using System.ComponentModel;
     3 using System.Collections.Generic;
     4 using System.Data;
     5 using System.Data.SqlClient;
     6 using System.Drawing;
     7 using System.Linq;
     8 using System.Text;
     9 using System.Windows.Forms;
    10  
    11 namespace sqltest1
    12 {
    13     public partial class Form1 : Form
    14     {
    15         public Form1()
    16         {
    17             InitializeComponent();
    18         }
    19  
    20         private void button1_Click(object sender, EventArgs e)
    21         {
    22             delData(textBox1.Text);
    23         }
    24  
    25         private void delData(string v)
    26         {
    27             SqlConnection conn = new SqlConnection("data source = .; initial catalog = test; User ID = sa; password = Ly00000000");
    28             conn.Open();
    29             SqlCommand cmd = conn.CreateCommand();
    30             cmd.CommandText = "deldata";
    31             cmd.CommandType = CommandType.StoredProcedure;
    32             //SqlParameter[] sps = new SqlParameter[] { new SqlParameter("@id",v) };
    33             cmd.Parameters.Add(new SqlParameter("@id", v));
    34             int i = cmd.ExecuteNonQuery();
    35             MessageBox.Show($"有{i}条数据受到影响!");
    36         }
    37  
    38         private void button2_Click(object sender, EventArgs e)
    39         {
    40             AddData(textBox2.Text, textBox3.Text);
    41         }
    42  
    43         private void AddData(string text1, string text2)
    44         {
    45             SqlConnection conn = new SqlConnection("data source = .; initial catalog = test; User ID = sa; password = Ly00000000");
    46             conn.Open();
    47             SqlCommand cmd = conn.CreateCommand();
    48             cmd.CommandText = "AddData";
    49             cmd.CommandType = CommandType.StoredProcedure;
    50             SqlParameter[] sps = new SqlParameter[] {
    51                 new  SqlParameter("@test1",text1),
    52                 new  SqlParameter("@test2",text2)
    53             };
    54             cmd.Parameters.AddRange(sps);
    55             int i = cmd.ExecuteNonQuery();
    56             MessageBox.Show($"有{i}条数据受到影响!");
    57         }
    58     }
    59 }

     
  • 相关阅读:
    为https请求配置ssl(不用keystore,直接用证书,rsa私钥,java代码)
    http请求对于List类型参数的处理
    java中string转ByteBuffer
    lua for循环如何从第0位开始
    lua中的cjson简单使用
    mongodb返回方便读的数据
    markdown简单插入图片
    #问题#java报Annotation processing is not supported for module cycles
    #问题#java报can't create non-static inner class instance
    git commit+push的完整步骤
  • 原文地址:https://www.cnblogs.com/heroysj/p/10868137.html
Copyright © 2011-2022 走看看