cshar_user_123
New member
- Joined
- Jan 22, 2018
- Messages
- 2
- Programming Experience
- 3-5
Hello,
I have a data validation implemented using C#. I have the validation at multiple cases. It works fine for the first case and it returns empty value for the subsequent test cases.
Please check the code below :
I have a data validation implemented using C#. I have the validation at multiple cases. It works fine for the first case and it returns empty value for the subsequent test cases.
Please check the code below :
public class dataValidation
{
SqlConnection conn = null;
SqlDataReader reader = null;
String uniqueId = Global.orderID;
String Order_Customer = "";
public customerValidation_new()
{
}
void Testone.Run()
{
Validate.AreEqual(Getcustomer(), Global.customer, Validate.DefaultMessage, false);
Global.customer = "";
}
public string Getcustomer()
{
try
{
conn = new SqlConnection();
conn.ConnectionString = "Data Source=*****;" +
"Initial Catalog=***;" +
"User id=**;" +
"Password=***";
conn.Open();
SqlCommand cmd = new SqlCommand("select CustomerID from TOrder where OrderId = @OrderID", conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@OrderID";
param.Value = uniqueId;
cmd.Parameters.Add(param);
reader = cmd.ExecuteReader();
while (reader.Read())
{
Order_Customer = reader["CustomerID"].ToString();
}
}
finally
{
// close reader
if (reader != null)
{
reader.Close();
}
// close connection
if (conn != null)
{
conn.Close();
}
}
switch (Order_Customer)
{
case "1":
return "John";
case "2":
return "Jim";
case "6":
return "Kate";
case "5":
return "David";
}
return Order_Customer;
}
}
Last edited by a moderator: