...

View Full Version : C#/ASP.NET Code Help



mdclaytz
08-12-2011, 10:45 AM
Hello all,

I'm new to this forum, and apologies if this is posted in the wrong place. I'm having some problems with some coding in the above languages. I have one particular problem, which I hope someone can help with.

I am trying to populate a field on a web form, based on the selections made in two drop down boxes (Combination of the two). On selecting the drop down values, it performs a lookup in the database to pull back a value, and populates a text field with this value.

I've got the SQL stored procedure covered, and the ASP.NET part of things. What I'm struggling on is the C# part. I have the following code so far:



private void GetPriority()
{
clsServerDetails objServerDetails = new clsServerDetails();
SqlConnection objSql = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter objDa = new SqlDataAdapter();

try
{
objServerDetails.setConnectionInformation("Default");
objSql.ConnectionString = objServerDetails.ConnectionString;
objSql.Open();
objCmd.CommandText = "CPortalGetPriority";
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.Add("@Impact", SqlDbType.NVarChar, 100).Value = ddImpact.Text;
objCmd.Parameters.Add("@Severity", SqlDbType.NVarChar, 100).Value = ddUrgency.Text;
// objCmd.Connection = objSQL;
objDa.SelectCommand = objCmd;

objDa.Fill(txtPriority);
}
catch (SqlException exSQL)
{
clsLogError.LogError("SqlException", exSQL.Number.ToString() + " " + exSQL.Message, System.Reflection.MethodBase.GetCurrentMethod().Name);
}
finally
{
objDa.Dispose();
objCmd.Dispose();
objSQL.Close();
objSQL.Dispose();
}
}


However I get the following error on my page:



CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments

Source Error:

Line 135: objDa.SelectCommand = objCmd;
Line 136:
Line 137: objDa.Fill(txtPriority);
Line 138: }
Line 139: catch (SqlException exSQL)



I'm assuming I can't just fill the text field with the output of the stored procedure, so what's the best way about going about this?

Thanks in anticipation of your replies.

Mark Clayton

dotnetmind
08-12-2011, 02:35 PM
I can't see where you declared the dataset txtpriority!

Try to use the following:


Dim ds As New DataSet
Dim da As New SqlDataAdapter(sqlCmd)
da.Fill(ds)

alykins
08-12-2011, 05:14 PM
I can't see where you declared the dataset txtpriority!

Try to use the following:


Dim ds As New DataSet
Dim da As New SqlDataAdapter(sqlCmd)
da.Fill(ds)


and to translate to C#



SqlDataSet ds_txtPriority = new SqlDataSet();

.....

objDa.Fill(ds_txtPriority);


note i did this free hand and without checking syntaxes



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum