Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using stored procedure to retrive value from database my code is as below

C#
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

SQL
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


please help to get values in datagridview
Posted
Updated 11-Jun-15 23:59pm
v2
Comments
[no name] 12-Jun-15 4:52am    
any error??
vikasmanhas 12-Jun-15 6:13am    
urgentbilltestTableAdapter bu = new urgentbilltestTableAdapter(sqlcmd);

getting error in this line how to resolve it so my code is run

1 solution

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[^]
 
Share this answer
 
Comments
vikasmanhas 12-Jun-15 5:46am    
i have to pass parameters in diffrent types one is int and other is date time. how can i do this
Torakami 12-Jun-15 6:00am    
where you want to pass those from where ? show me the highlighted part
vikasmanhas 12-Jun-15 6:13am    
pass these from store procedure @Vno and @vdt

know i got error in line
urgentbilltestTableAdapter bu = new urgentbilltestTableAdapter(sqlcmd);
dont know the error. plz help
vikasmanhas 12-Jun-15 6:15am    
i used a textbox and a datetimepicker textbox to get values and pass them to storedprocedure amd date time to get date
vikasmanhas 12-Jun-15 7:01am    
know i got error keyword not support datasource

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900