sqlDataAdapter filling Dataset

M

Michael Jones

Ok.......... I'm trying to fill a parameterized table onto a Dataset
via a sqlDataAdapter. It works fine if I fill the Dataset with all
the column fields. What I want to do though is to only fill the
Dataset with certain values from my DateTimeIn column (i.e. only files
where DateTimeIn == user-defined date). This isn't working.

I'm sure my query is correct because I've used the same code in
different projects:

SELECT TransIdentity, DateTimeIn, DateTimeOut, RevisedDate FROM
TransactionData WHERE (DateTimeIn = @Param2)

What I think it is is that the user-inputed date is not being read
right as a parameter. Does it matter that the txtDateParameter.Text
is not in DateTime format? I don't think so.

private void btnShow_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value =
txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Can someone help me out, I can't figure out what's going on.

Let me know if you need some more info.

Thanks guys,

Frustrated Mike
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Michael,

Some observations:

a) You should add the Parameter object to the Command's Parameters
collection first and then specify its value second (not sure this is a
necessary step but at least it has always worked for me that way).
b) If you specify the parameter as @Param2 in the SQL, it should be named
the same in the Command's Parameters collection.
 
M

Michael Jones

Yes I did do that. Thanks Dmitriy. I don't understand what's going
on. No error or inforamtion comes up when I try to preview the data
via the DataAdapter. And, when the application is running and I hit
my Submit button, I get a System.IndexOutOfRangeException where I set
my parameter equal to the textbox text. This happens no matter what
kind of information I input in the textbox. Here's where it errors:

private void btnShow_Click(object sender, System.EventArgs e)
{
********** sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value
= txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Any idea?................thanks again

Dmitriy Lapshin said:
Hi Michael,

Some observations:

a) You should add the Parameter object to the Command's Parameters
collection first and then specify its value second (not sure this is a
necessary step but at least it has always worked for me that way).
b) If you specify the parameter as @Param2 in the SQL, it should be named
the same in the Command's Parameters collection.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Michael Jones said:
Ok.......... I'm trying to fill a parameterized table onto a Dataset
via a sqlDataAdapter. It works fine if I fill the Dataset with all
the column fields. What I want to do though is to only fill the
Dataset with certain values from my DateTimeIn column (i.e. only files
where DateTimeIn == user-defined date). This isn't working.

I'm sure my query is correct because I've used the same code in
different projects:

SELECT TransIdentity, DateTimeIn, DateTimeOut, RevisedDate FROM
TransactionData WHERE (DateTimeIn = @Param2)

What I think it is is that the user-inputed date is not being read
right as a parameter. Does it matter that the txtDateParameter.Text
is not in DateTime format? I don't think so.

private void btnShow_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value =
txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Can someone help me out, I can't figure out what's going on.

Let me know if you need some more info.

Thanks guys,

Frustrated Mike
 
D

Dmitriy Lapshin [C# / .NET MVP]

Michael,

It seems you are trying to access the parameter named DateTimeIn while you
have a parameter named @Param2 in the query. Next, you might set a
breakpoint on the following line:
sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value
= txtDateParameter.Text;

and ensure the Parameters collection really contains this parameter. Even
more, you should explore this collection in the Watch window to find out if
there are any parameters at all and what are their names.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Michael Jones said:
Yes I did do that. Thanks Dmitriy. I don't understand what's going
on. No error or inforamtion comes up when I try to preview the data
via the DataAdapter. And, when the application is running and I hit
my Submit button, I get a System.IndexOutOfRangeException where I set
my parameter equal to the textbox text. This happens no matter what
kind of information I input in the textbox. Here's where it errors:

private void btnShow_Click(object sender, System.EventArgs e)
{
********** sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value
= txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Any idea?................thanks again

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Hi Michael,

Some observations:

a) You should add the Parameter object to the Command's Parameters
collection first and then specify its value second (not sure this is a
necessary step but at least it has always worked for me that way).
b) If you specify the parameter as @Param2 in the SQL, it should be named
the same in the Command's Parameters collection.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Michael Jones said:
Ok.......... I'm trying to fill a parameterized table onto a Dataset
via a sqlDataAdapter. It works fine if I fill the Dataset with all
the column fields. What I want to do though is to only fill the
Dataset with certain values from my DateTimeIn column (i.e. only files
where DateTimeIn == user-defined date). This isn't working.

I'm sure my query is correct because I've used the same code in
different projects:

SELECT TransIdentity, DateTimeIn, DateTimeOut, RevisedDate FROM
TransactionData WHERE (DateTimeIn = @Param2)

What I think it is is that the user-inputed date is not being read
right as a parameter. Does it matter that the txtDateParameter.Text
is not in DateTime format? I don't think so.

private void btnShow_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value =
txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Can someone help me out, I can't figure out what's going on.

Let me know if you need some more info.

Thanks guys,

Frustrated Mike
 
M

Michael Jones

Yes I did do that. Thanks Dmitriy. I don't understand what's going
on. No error or inforamtion comes up when I try to preview the data
via the DataAdapter. And, when the application is running and I hit
my Submit button, I get a System.IndexOutOfRangeException where I set
my parameter equal to the textbox text. This happens no matter what
kind of information I input in the textbox. Here's where it errors:

private void btnShow_Click(object sender, System.EventArgs e)
{
********** sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value
= txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Any idea?................thanks again

Dmitriy Lapshin said:
Hi Michael,

Some observations:

a) You should add the Parameter object to the Command's Parameters
collection first and then specify its value second (not sure this is a
necessary step but at least it has always worked for me that way).
b) If you specify the parameter as @Param2 in the SQL, it should be named
the same in the Command's Parameters collection.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Michael Jones said:
Ok.......... I'm trying to fill a parameterized table onto a Dataset
via a sqlDataAdapter. It works fine if I fill the Dataset with all
the column fields. What I want to do though is to only fill the
Dataset with certain values from my DateTimeIn column (i.e. only files
where DateTimeIn == user-defined date). This isn't working.

I'm sure my query is correct because I've used the same code in
different projects:

SELECT TransIdentity, DateTimeIn, DateTimeOut, RevisedDate FROM
TransactionData WHERE (DateTimeIn = @Param2)

What I think it is is that the user-inputed date is not being read
right as a parameter. Does it matter that the txtDateParameter.Text
is not in DateTime format? I don't think so.

private void btnShow_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters["DateTimeIn"].Value =
txtDateParameter.Text;
dsTimeIn1.Clear();
sqlDataAdapter1.Fill(dsTimeIn1);
}

Can someone help me out, I can't figure out what's going on.

Let me know if you need some more info.

Thanks guys,

Frustrated Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top