Here is what I have so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Server;
using System.IO;
using System.Data.SqlClient;
namespace StoredProcedureExecution_Pieter_Bekker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
LoadCombo();
}
catch (Exception)
{
err.SetError(cboSelectDatabase,"Problem loading databases. Please contact the system administrator.");
}
}
private void LoadCombo()
{
String conxString = (@"Data Source = WOLF-PC\WOLF; Integrated Security=True;");
using (SqlConnection conn = new SqlConnection(conxString))
{
conn.Open();
DataTable tblDatabases = conn.GetSchema("Databases");
conn.Close();
foreach (DataRow row in tblDatabases.Rows)
{
cboSelectDatabase.Items.Add(row["database_name"]);
}
}
}
private void cboSelectDatabase_SelectedIndexChanged(object sender, EventArgs e)
{
btnLoadProcedures.Enabled = true;
}
private void btnLoadProcedures_Click(object sender, EventArgs e)
{
//This is where I need some help...
}
}
}
PieterPosted Jun 4, 2012, 11:28 AM
private void LoadStoredProcedures()
Thanks again for the help! I'll post the source code for the project if anyone wants it.
Jignesh TrivediPosted Jun 4, 2012, 12:07 AM
to get list of SP in selected database use must pass database name as a initial catalog in connection string.
replace bold character with database name which are selected by other combo.
Try following...
private void btnLoadProcedures_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=WOLF-PC\WOLF;Initial Catalog=" + databasename + ";User ID=useIdr;Password=password;MultipleActiveResultSets=True");
con.Open();
DataSet _dataset = new DataSet();
string commandText = "select name from sys.objects where type = 'P'";
SqlDataAdapter datAd = new SqlDataAdapter(commandText, con);
datAd.Fill(_dataset, "Test");
con.Close();
DataTable dt = _dataset.Tables["Test"];
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "name";
}
hope this will help u.