'How to fill a datagridView with my stored procedure on load
I have this stored procedure that selects the top 10 results from its inner join
CREATE PROCEDURE SP_SELECT_DOCS_WHERE_JOBID_STATUS
@JobID INT,
@BatchID INT
AS
BEGIN
SELECT top(10) i.*
FROM jobtable AS j
INNER JOIN batchtable AS b ON j.JobID = b.JobID
INNER JOIN imgtable AS i ON i.BatchID = b.BatchID
END
What I don´t know why it's not working is when I run the app the datagrid is just empty.
This next code is on my dataAccess class
public DataTable SP_SELECT_DOCS_WHERE_JOBID_STATUS_IBML1(int JobID, int BatchID)
{
try
{
ManageConnectionStateIbml1();
SqlCommand command = new
SqlCommand("SP_SELECT_DOCS_WHERE_JOBID_STATUS", connectionIBML1);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@JobId", JobID);
command.Parameters.AddWithValue("@BatchId", BatchID);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds.Tables[0];
}
catch (Exception ex)
{
throw ex;
}
finally
{
ManageConnectionStateIbml1();
connectionIBML1.Close();
}
}
And finally there is my Form file that I am trying to fill the dgv
private void FillDGVDocs(int JobID, int BatchID)
{
dataGridViewDocumentos.DataSource = null;
dataGridViewDocumentos.Columns.Clear();
dataGridViewDocumentos.Refresh();
DataTable dt = da.SP_SELECT_DOCS_WHERE_JOBID_STATUS_IBML1 (JobID, BatchID);
dataGridViewDocumentos.DataSource = dt;
dataGridViewDocumentos.Columns[1].HeaderText = "Caixa";
dataGridViewDocumentos.Columns[2].HeaderText = "DOC";
dataGridViewDocumentos.Columns[3].HeaderText = "ID";
dataGridViewDocumentos.Columns[4].HeaderText = "PROC";
}
Thanks in advance guys.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|