我在dt(0)收到错误,说dt是一个变量但是像方法一样使用。 谢谢你的帮助。我知道这看起来很简单,但我无法弄清楚。非常感谢您的帮助。
private void pubSelectHL7Server()
{
try
{
//-> if valid ip address, no need to get from database.
if (HL7ServerIP.Trim().Split('.').Length == 4)
return;
//Dim ServiceName As String = String.Empty
//ServiceName = If(My.Settings.ServiceName.ToString.Length = 0, "IMG_JES", My.Settings.ServiceName)
classDataSource mClsDs = new classDataSource();
//mClsDs.Add("HL7_SelectServer", "@pServiceName", SqlDbType.NVarChar, 10, ServiceName.ToString());
mClsDs.Add("HL7_SelectServer", "@pServiceName", (Char)SqlDbType.NVarChar, 10, ServiceName);
using (DataTable dt = mClsDs.GetRs("LABIMAGEDB", "Constultation").Tables[0])
{
if (dt != null && dt.Rows.Count > 0)
{
HL7ServerIP = dt(0)("ServerIP").ToString();
HL7SendPort = dt(0)("SendPort").ToString.Trim;
TempLogFolder = dt(0)("TempLogFolder").ToString.Trim;
StopSendPort = Module1.CheckNullIntegerToBoolean(dt(0)("StopSendPort"));
}
}
writeMessage("ServiceName " + ServiceName, true);
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
ModuleHl7.WriteExeptionLog(ex, "-PubSelectHL7sERVER. Error Getting Connection Info");
}
}
答案 0 :(得分:2)
我认为您希望DataTable
包含一个DataRow
,并且您希望访问它的字段。然后你可以通过DataTable.Rows[0].Field
获取它们:
HL7ServerIP = dt.Rows[0].Field<string>("ServerIP");
请注意,您不能使用圆括号(如在VB.NET中)访问数组或列表,而是使用方括号。