Re: Trouble with databinding

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is a snippet for a basic query with ADO.NET.

using System;
using System.Data;
using System.Data.SqlClient;

class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");

SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM
Categories";

nwindConn.Open();

SqlDataReader myReader = catCMD.ExecuteReader();

while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0),
myReader.GetString(1));
}

myReader.Close();
nwindConn.Close();
}
}



Hayden Kirk wrote:
Thanks for responding Brennan.

This is working perfectly. I was wondering though, what is the best way to
go about getting the data from the mssql database. I only need to check to
see if their email address already exists or not, possibly delete it if they
wish to unsubscribe. Can I use the sqldatasource control for this? Or is is
better to code this by hand?

I was wondering if someone could give me a quick example of doing it by
hand.

Thanks,

"Brennan Stehling" <offwhite@xxxxxxxxx> wrote in message
news:1157942127.738960.146550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
What you need to do is handle the NextButtonClick and
PreviousButtonClick events. In those events you can check the value
for the ActiveStepIndex which will coorespond with each of your steps.
If the right step is the current one you can run your check against the
database. If you want to cancel the step you can set the Cancel
property on the event to true.

Here is a code snippet.

protected void Wizard1_NextButtonClick(object sender,
System.Web.UI.WebControls.WizardNavigationEventArgs e)
{
bool isEmailValid = FindEmail(txtEmail.Text);
e.Cancel = ! isEmailValid();
}

You may also want to attach a custom validator to the email textbox and
then you can simply ask the validator if it is valid. It will then
automatically display the error indicator, like a red star next to the
textbox.

Brennan Stehling
http://brennan.offwhite.net/blog/

Hayden Kirk wrote:
Hi,

I'm trying to add databinding to the wizard control. Basically a user is
entering their email address and I want to validate this to a sql
database
when the hit next but I cannot get this to work.

Any idea how I would go about doing this?

Thanks in advance

--

- Hayden Kirk


.



Relevant Pages

  • Re: Crud Design Question
    ... and I don't need all the database functionallity. ... public static string ConnectionString {get {return ... public static void Load ... private string connectionString; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Crud Design Question
    ... since you will use only one database, ... you could put the connectionstring in a single class, ... Maybe you should provide a private constructor, wich is called by the Load ... public static void Load ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PHP] Displaying files from database
    ... On 3/28/07, Philip Thompson wrote: ... It loads into the database fine. ... Downloading looks like: ...
    (php.general)
  • Re: [PHP] Displaying files from database
    ... It loads into the database fine. ... Downloading looks like: ...
    (php.general)
  • Re: A little mystery
    ... a database (with "Set Altenate to" and ??). ... Sometime ago I picked up here this little snippet ... Opera's revolutionary e-mail client: http://www.opera.com/m2/. ...
    (comp.lang.clipper)