Hi, I was able to use PsychoCoder's code for C# and SQL for working with BindingSources and DataGridViews, but modifying that code to work with DataSets and pulling individual fields has proven a tad more complicated...
What I'd like to do is populate text boxes with a single entry result ... Here's my code for one of those instances...
CODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace MassageProCS
{
public partial class LogInForm : Form
{
public int TID = 0;
public LogInForm()
{
InitializeComponent();
}
private void LogInForm_Load(object sender, EventArgs e)
{
}
private void logInButton_Click(object sender, EventArgs e)
{
string sSQL = "ValidateLogin";
SqlConnection cnGetRecords = new SqlConnection(DataAccess.GetConnectionString("MassageProCS.Properties.Settings.MassageProConnectionString"));
SqlCommand cmdGetRecords = new SqlCommand();
SqlDataAdapter daGetRecords = new SqlDataAdapter();
DataSet dsGetRecords = new DataSet();
cmdGetRecords.Parameters.Clear();
cmdGetRecords.CommandText = sSQL;
cmdGetRecords.CommandType = CommandType.StoredProcedure;
cmdGetRecords.Parameters.AddWithValue("@TherapistName", therapistNameTextBox.Text);
cmdGetRecords.Parameters.AddWithValue("@TherapistPassword", therapistPasswordTextBox.Text);
DataAccess.HandleConnection(cnGetRecords);
daGetRecords.SelectCommand = cmdGetRecords;
daGetRecords.Fill(dsGetRecords);
string tempID = dsGetRecords.Tables["Therapists"].Columns["TherapistID"].ToString();
TID = Convert.ToInt16(tempID);
if (TID > 0)
{
// Temporary, for testing purposes...
MessageBox.Show(TID.ToString());
}
else
{
MessageBox.Show("You have entered a wrong username and/or password.");
}
}
}
}
But I am coming up with this error...
QUOTE
Fill: SelectCommand.Connection property has not been initialized.
For this line of code...
CODE
daGetRecords.Fill(dsGetRecords);