No Row at Position 0

Hi, I’m trying to set some values on some text boxes through a BAQ, using a part number as an execution parameter. This method is called on an EpiViewNotification event too. Here’s the code:

	public void getweight()
	{
		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();		
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("QuoteWeight");
		qeds.ExecutionParameter.Clear();
	
			if (txtPartNumber.Text == "")
			{
			
			}
			else
			{
			qeds.ExecutionParameter.AddExecutionParameterRow("PartNum", txtPartNumber.Text, "nvarchar", false, Guid.NewGuid(), "A");
			}

			dqa.ExecuteByID("QuoteWeight", qeds);
			if (( dqa.QueryResults.Tables["Results"].Rows.Count > -1))
			{
			txtweight.Value = ((decimal)dqa.QueryResults.Tables["Results"].Rows[0][0]);
			txttotweight.Value = (((decimal)dqa.QueryResults.Tables["Results"].Rows[0][0]) * Convert.ToInt32(numExpectedQty.Value));
			}
			
	}

It gives me an error that no row exists in position 0 unless I omit the lines that grab the values and places them in txtweight and txttotweight… but those shouldn’t even fire if my BAQ returns zero rows in the IF statement that those lines are contained in. Maybe I’m missing something or my code is just wrong. Appreciate any help or advice. Thank you!

What hapens if you hardcode the values instead of trying to use the query results? Basically, which row is missing?

			txtweight.Value = 1.5;

I didn’t meant to delete that post, but basically split up your parts. Make sure the assigning is working on it’s own, and make sure your BAQ results are working on their own. Then combine them in the code.

It fires correctly if I enter in an existing part number but the form I’m using this on is the quote entry screen. Sometimes the part number they enter doesn’t exist yet in part maintenance resulting in 0 rows returned in the BAQ. I only want it to fire if the BAQ returns a row. The BAQ only ever returns but 1 row and 1 columns containing the entered parts net weight.

0 rows is greater than -1. Rows.Count is not an index, it’s a count.

1 Like

Durp lol. Okay, I’ll give it a go. I’m sure that’s my issue now that you pointed it out.

1 Like

Well now I feel like an idiot lol… Thank you!

1 Like