I have created a method with a string "test" that holds my SqlCommand query. test = '201813'
public void temp()
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT LEFT(CONVERT(VARCHAR(10),GETDATE(),120),4)+ CAST((DATEPART(ISOWK,GETDATE()) - 2) AS NVARCHAR(2))", con);
con.Open();
string test = (string)cmd.ExecuteScalar();
con.Close();
}
}
The question now is How can I reuse this string in my following rowdatabound event?
protected void gwPlanning_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0)
{
//Translate header text
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[12].Text = test.ToString();
}
}
}
I'm trying to use e.Row.Cells[12].Text = **test.ToString();
Can anyone help me on what im doing wrong?