如何使用存储过程在gridview中检索数据 [英] how to retrive data in gridview using stored procedure

查看:63
本文介绍了如何使用存储过程在gridview中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用存储过程从数据库中检索值我的代码如下所示



i am using stored procedure to retrive value from database my code is as below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO.Compression;

namespace WindowsFormsApplication2_testbill_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
           SqlConnection sqlcon = new SqlConnection("DataSource=SQLEXPRESS"+"InitialCatalog=esdata"+"Integrated Security=True");
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("urgentbill",sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@Vno", textBox1.Text);
sqlcmd.Parameters.AddWithValue("@Vdt",dateTimePicker1.Text);       
           
sqlcmd.ExecuteNonQuery();
urgentbilltestTableAdapter bu = new urgentbilltestTableAdapter(sqlcmd);
    esdataDataSet4 ds = new esdataDataSet4();
bu.Fill(ds);

               
           if (ds.Tables[0].Rows.Count > 0)
                {
                    dataGridView1.Visible = true;
                    dataGridView1.DataSource = ds.Tables[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
           // finally
           // {
            //    Sqlcon.close();    
           // }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text="";
        }

        
        
        }
    }



我的存储过程是




my stored procedure is

create procedure urgentbilltest
(
@Vno int,
@Vdt smalldatetime
)
as
begin
select  item.location, sum(salepurchase2.qty) AS QTY,sum(salepurchase2.fqty) AS FQTY, item.name, SALEPURCHASE2.MRP, item.pack, 
item.compname, salepurchase2.batch, salepurchase2.expiry from
 salepurchase2 inner join item on salepurchase2.itemc=item.code 
 where ((salepurchase2.vdt= @Vdt+'%'))  and  salepurchase2.vtype in ('Sb', 's1') and (salepurchase2.vno in ( @Vno+'%'))
 group by salepurchase2.batch,
 item.location, item.name, item.pack, item.compname, SALEPURCHASE2.MRP, salepurchase2.expiry order by item.location
 end





请帮助获取值datagridview



please help to get values in datagridview

推荐答案

你有没有收到任何错误?



查看以下两个显示如何显示的例子使用storeprocedure记录到gridview





http://www.aspsnippets.com/Articles/Bind-data-to-ASPNet-GridView-using-Stored-Procedure.aspx [< a href =http://www.aspsnippets.com/Articles/Bind-data-to-ASPNet-GridView-using-Stored-Procedure.aspx\"target =_ blanktitle =New Window> ^ ]





http://asp.net-informations.com/gridview/procedure.htm [ ^ ]
Did you get any error ??

check below two examples which shows how to display record into gridview using storeprocedure


http://www.aspsnippets.com/Articles/Bind-data-to-ASPNet-GridView-using-Stored-Procedure.aspx[^]


http://asp.net-informations.com/gridview/procedure.htm[^]


这篇关于如何使用存储过程在gridview中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆