vikas manhas

vikas manhas

  • NA
  • 4
  • 852

how to retrive data in gridview using stored procedure

Jun 12 2015 6:25 AM
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("urgentbilltest",sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@Vno", textBox1.Text);
sqlcmd.Parameters.AddWithValue("@Vdt",dateTimePicker1.Value.Date);
sqlcmd.ExecuteNonQuery();
//urgentbilltestTableAdapter bu = new urgentbilltestTableAdapter(sqlcmd);
//urgentbilltestTableAdapter bu = new esdataDataSet4TableAdapters.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
 
 
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
 
 
 

Answers (1)