I have a Windows form application that I am building. This form is being designed so that every 5 minutes, it runs a stored procedure that has two variables.
The form has a Combo Box control that runs a query against the same data as the Stored procedure. It takes the Wayside Name and State separated by Comma and displays it in the Combo Box Dropdown list. With the SelectedItem.Text property I populate two text boxes with the name and the State as the parameters for the Stored Procedure. What I want to happen is when I select an item from the control, and fills the two text boxes, and I click a Submit button, I want the two parameters to pass to the Stored procedure and display the results.
Lastly, I need it to append to a .csv file so as to evaluate performance of the field equipment.
I have been searching for the past week and tried many different solutions for this that have been suggested previously.
The problem I am having is, that no matter what I put in the text boxes, the datagridview never populates.
This is the stored procedure;
USE [NMS_RT]
GO
/****** Object: StoredProcedure [dbo].[GrpCoverage] Script Date: 09/17/2013 12:00:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ====================================================
-- Author: Brian S. Cook
-- Create date: 09/03/2013
-- Description: Single Group Coverage Search Query.
-- ====================================================
ALTER PROCEDURE [dbo].[GrpCoverage]
AS
BEGIN
SET NOCOUNT ON;
SELECT ( Grp.name + ',' + Grp.state ) AS Wayside,
( SELECT 'G'+ SUBSTRING(CONVERT(VARCHAR(100), CAST(WEA AS DECIMAL(38, 2))), 3, 3) + '/'+ SUBSTRING(CONVERT(VARCHAR(100), CAST(WEA AS DECIMAL(38, 2))), 6, 3)
) AS 'Group ID',
( SELECT [Name] + ',' + [State]
FROM [NMS_CFG2].[dbo].[Base_Equipment]
WHERE Base_Equip_Address = ( SELECT TOP 1
Base_Equip_Address
FROM [NMS_CFG2].[dbo].[be_xref_oa]
WHERE x_pbase = master.dbo.ufnStringToPbase([base1])
)
) + ' ( ' + [base1] + ')' AS 'Primary',
CAST(Cov.SSI1 as VARCHAR(3)) as 'Primary SSI',
( SELECT [Name] + ',' + [State]
FROM [NMS_CFG2].[dbo].[Base_Equipment]
WHERE Base_Equip_Address = ( SELECT TOP 1
Base_Equip_Address
FROM [NMS_CFG2].[dbo].[be_xref_oa]
WHERE x_pbase = master.dbo.ufnStringToPbase([base2])
)
) + ' ( ' + [base2] + ')' AS 'Secondary',
CAST(Cov.SSI2 as VARCHAR(3)) as 'Secondary SSI',
( SELECT [Name] + ',' + [State]
FROM [NMS_CFG2].[dbo].[Base_Equipment]
WHERE Base_Equip_Address = ( SELECT TOP 1
Base_Equip_Address
FROM [NMS_CFG2].[dbo].[be_xref_oa]
WHERE x_pbase = master.dbo.ufnStringToPbase([base3])
)
) + ' ( ' + [base3] + ')' AS 'Tertiary',
CAST(Cov.SSI3 as VARCHAR(3)) as 'Tertiary SSI',
CAST([Date_Time] AS DATE) AS Date
FROM [NMS_RT].[dbo].[RT_Group_Status] AS Cov
INNER JOIN [NMS_CFG2].[dbo].[ATCS_Group] AS Grp
ON Grp.Group_Address = Cov.[WEA]
ORDER BY [Group ID], Wayside
ENDHere is my Form Code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SSI_DataGrabber
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'nMS_RTDataSet1.GrpCoverageAll' table. You can move, or remove it, as needed.
this.grpCoverageAllTableAdapter.Fill(this.nMS_RTDataSet1.GrpCoverageAll);
}
private void BtnStartClick(object sender, EventArgs e)
{
}
private DataTable GetRecords()
{
SqlConnection conn = new SqlConnection("Data Source=servername;Initial Catalog=NMS_RT;Persist Security Info=True;User ID=user;Password=password");
conn.Open();
SqlCommand cmd = new SqlCommand("SingleGrpCoverage", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@WaySide", SqlDbType.VarChar).Value = TxtWayside.Text;
cmd.Parameters.Add("@ST", SqlDbType.Date).Value = TxtState.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
dgvWaysideGrid.DataSource = ds.Tables[0];
//dgvWaysideGrid.DataBindings();
return ds.Tables[0];
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
TxtWayside.Text = comboBox1.Text;
}
}
}Thanks!