ahmed sa

ahmed sa

  • NA
  • 289
  • 129k

Return result from getdate function from sql to c# give wron

Apr 9 2015 4:17 AM

Hi guys i have windows form application in this form i need to show date of server 

not date of client so that i write following function 

stored procedure 

create proc datetoday1
as
select getdate()as datetoday

function in c#

public string GetDateProcesses(string ConnectionString)
{
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "datetoday1";
con.Open();
string getdate=Convert.ToString(cmd.ExecuteNonQuery());
con.Close();
return getdate;
}

in interface 

FleetManagment.Fleet fleetAccountNo = new FleetManagment.Fleet();
label3.Text = fleetAccountNo.GetDateProcesses("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "");

but it return -1 not date of server what is wrong in my code

and what modification in code to return true result


Answers (7)