I'm actually working on some DB connection and I'm so using a SqlDataReader
.
I already created some snippets to help me write faster when it comes to handling DBNULL values.
I was wondering if it is possible to create a snippet for C# that can add lines depending on something like a parameter?
What I'm actually thinking is something like :
string example1 = "";
string example2 = "";
string example3 = "";
try
{
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
if(reader["example1"] != DBNULL.Value)
{
example1 = reader["example1"].ToString();
}
else
{
example1 = "";
}
if(reader["example2"] != DBNULL.Value)
{
example2 = reader["example2"].ToString();
}
else
{
example2 = "";
}
if(reader["example3"] != DBNULL.Value)
{
example3 = reader["example3"].ToString();
}
else
{
example3 = "";
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
Is there a way to get it using a snippet typing something like "reader3" where 3 determine the number of fields? (else than just create a bunch of snippet for each possible case)
I tried to search for such a thing, but I didn't find anything, so I guess it might not be possible, but still want to ask, would save a lot of time.