Hi, i am trying to pass the value of a text box to a sql statement, the only thing is that the sql statement is located in a different file to where the text boxes are. i have had some trouble in the past with this, as when i call the value in my sql statement i get an error stating that " an object reference is required for the non static field, mehtod or property", i have changed the modifiers of my text box to pubic and this still has not worked, our there another other soultions?
This is were i get my values that i want to put into the sql statement
txtfrom.Text = dtResults.Rows[0]["asset_open_per"].ToString(); // Date from - Default to Database value
this.txtto.Text = DateTime.Today.ToString("yyyyMM"); // Date To - Current Year and Month
{
dtResults = SQLMETHODS.GetPostings2(strAssetNumber, PeriodFromV, PeriodToV);
}
this is my sql statement and i get the error from the "periodFrom" & "periodTo"
public static DataTable GetPostings2(string AssetNumberV, string PeriodFromV, string PeriodToV)
public static DataTable GetPostings2(string AssetNumberV, string PeriodFromV, string PeriodToV)
{
DataTable dtGetPostings2;
try
{
dtGetPostings2 = new DataTable("GetPostings");
SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);
AssetNumber.Value = AssetNumberV;
SqlParameter PeriodFrom = new SqlParameter("@PeriodFrom", SqlDbType.VarChar, 6);
PeriodFrom.Value = frmAssetPostings.txtfrom.Text;
SqlParameter PeriodTo = new SqlParameter("@PeriodTo", SqlDbType.VarChar, 6);
PeriodTo.Value = frmAssetPostings.txtto.Text;
SqlCommand scGetPostings2 = new SqlCommand("SELECT * FROM [POSTING] WHERE [ASSET_NO] = @AssetNumber And PERIOD >= @PeriodFrom AND PERIOD <= @PeriodTo ORDER by PERIOD, JOUR_REF, JOUR_LINE", DataAccess.AssetConnection);
SqlDataAdapter sdaGetPostings2 = new SqlDataAdapter();
sdaGetPostings2.SelectCommand = scGetPostings2;
sdaGetPostings2.Fill(dtGetPostings2);
return dtGetPostings2;
}
catch (Exception ex)
{
MessageBox.Show("Error Retriving Posting Details: Processed with this error:" + ex.Message);
return null;
}
} {