I have a code which gives me error as
Data is Null. This method or property cannot be called on Null values
if (reader.Read())
{
return reader.GetString(0);
}
return null;
Below is the full code
[WebMethod]
public static string GetCurrentToBin(string ToBin, int warehouseId)
{
var connectionString = ConfigurationManager.ConnectionStrings["SqlConn"].ToString();
using(var conn = new SqlConnection(connectionString))
{
const string queryString = "exec sp_P_WMS_Stock_Adj_Validation_Proc @Bin , @warehouse";
var sqlCommand = new SqlCommand(queryString , conn);
sqlCommand.Parameters.AddWithValue("@Bin",ToBin);
sqlCommand.Parameters.AddWithValue("@warehouse", warehouseId);
conn.Open();
var reader = sqlCommand.ExecuteReader();
if (reader.Read())
{
return reader.GetString(0);
}
return null;
}
}