|
|
|
asp.net ช่วยดูเรื่องตัวแปร array c# หน่อยครับ : Error : Use of unassigned local variable |
|
|
|
|
|
|
|
คือผมเขียน Windows service แล้ว มันติดตรงมันไม่รู้จัก array ตัวนี้ครับ ArrData
คอมไพร์แล้วมัน error บรรทัดนี้ครับ if(ArrData != null) ตอน ทำใน win form ก็ปกตินะครับ ช่วยดูให้น่อยครับ
นี่ Error ครับ
Code
Error : Use of unassigned local variable 'ArrData'
Code (C#)
public static string getDataFromGeneratedCSV()
{
SqlConnection objConn = new SqlConnection();
string strConnString = null;
string strSQL = null;
strConnString = "server=.;database=SMF570_Server;Trusted_Connection=false;uid=sa;pwd=mpa123;";
objConn.ConnectionString = strConnString;
objConn.Open();
strSQL = "SELECT TOP(1000) * FROM VEHICLE_WEB_SERVICE";
bool Isfind = false;
SqlDataAdapter da;
DataSet ds = new DataSet();
string[] ArrData;
try
{
if (Isfind == true)
{
ds.Tables["strSQL"].Clear();
}
da = new SqlDataAdapter(strSQL, objConn);
da.Fill(ds, "strSQL");
int i = 0;
if (ds.Tables["strSQL"].Rows.Count != 0)
{
Isfind = true;
ArrData = new string[ds.Tables["strSQL"].Rows.Count];
for (i = 0; i < ds.Tables["strSQL"].Rows.Count; i++)
{
ArrData[i] = ds.Tables["strSQL"].Rows[i]["V_WEB_SERVICE"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_LATITUDE"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_LONGITUDE"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_DIRECTION"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_SPEED"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_GPSDATE_UTC"].ToString() + "," +
ds.Tables["strSQL"].Rows[i]["VLCTP_SATELLITE"].ToString();
}
//ArrData[i] = ds.Tables["strSQL"].Rows[0]["V_WEB_SERVICE"].ToString() + " ทะเบียน " + ds.Tables["strSQL"].Rows[0]["V_LICENSE_NO"].ToString();
}
objConn.Close();
objConn = null;
}
catch(Exception e)
{
if (Properties.Settings.Default.logging == true)
{
Logger.LogMessageToFile("Error Connecttion to Database: " + e.Message);
}
}
if(ArrData != null)
{
try
{
string tmp = "";
char[] token = { ',' };
ProbeContainerEntity container = new ProbeContainerEntity();
container.ProbePointData = new List<ProbePointEntity>();
container.ProviderName = Properties.Settings.Default.provider;
int cntr = 0;
int j = 0;
for (j = 0; j < ArrData.Length ; j++)
{
tmp = ArrData[j];
ProbePointEntity probePoint = new ProbePointEntity();
string[] values = tmp.Split(token);
probePoint.ProbeID = values[0];
probePoint.Lat = double.Parse(values[1]);
probePoint.Lon = double.Parse(values[2]);
probePoint.Heading = int.Parse(values[3]);
probePoint.Speed = values[4];
probePoint.Timestamp = values[5];
probePoint.Satellites = int.Parse(values[6]);
//ArrData[i] = ds.Tables["strSQL"].Rows[i]["V_WEB_SERVICE"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_LATITUDE"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_LONGITUDE"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_DIRECTION"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_SPEED"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_GPSDATE_UTC"].ToString() + "," +
//ds.Tables["strSQL"].Rows[i]["VLCTP_SATELLITE"].ToString() + "," +;
container.ProbePointData.Add(probePoint);
}
//returns a string of the json data.
//null and default values do not get put into json object.
return JsonConvert.SerializeObject(container, Formatting.None,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
});
}
catch (Exception e)
{
Logger.LogMessageToFile("Error Connecttion to Database(Catch): " + e.Message);
}
}
return null;
}
Tag : ASP.NET MySQL, C#
|
|
|
|
|
|
Date :
2013-05-22 10:52:32 |
By :
Alone21st |
View :
3900 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
string[] ArrData = null;
ทำการ assigned ค่าให้ด้วยครับ
|
|
|
|
|
Date :
2013-05-22 11:49:21 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|