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
Shubham KumarPosted Apr 9, 2015, 12:40 PM
Shubham KumarPosted Apr 9, 2015, 12:38 PM
string date;
string str1 = "select GetaDate() as Date'"'";
SqlCommand cmd = new SqlCommand(str1, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())////use while or if which u want
{
date= dr["Date"].ToString() )
}
return date;
i just write this but an not debug it so please debug it
ahmed saPosted Apr 9, 2015, 9:52 AM
Shubham KumarPosted Apr 9, 2015, 9:01 AM
just exexut that you got the answer
ahmed saPosted Apr 9, 2015, 6:33 AM
Shubham KumarPosted Apr 9, 2015, 4:26 AM
Shubham KumarPosted Apr 9, 2015, 4:24 AM