Use of unassigned local variable 'xxx'

Posted by Tomislav on Stack Overflow See other posts from Stack Overflow or by Tomislav
Published on 2010-05-19T13:12:04Z Indexed on 2010/05/19 14:10 UTC
Read the original article Hit count: 228

I'm writing a database importer from our competitors to ours database:) I have a code generator which create Methods form import to our database like

public void Test_Import_Customer_1()

 // variables
 string conn;
 string sqlSelect;
 string sqlInsert;

 int extID;
 string name;
 string name2;
 DateTime date_inserted;

 sqlSelect="select id,name,date_inserted from table_competitors_1";
 oledbreader reader = new GetOledbRader(sqlString,conn);
 while (reader.read())
 {
  name=left((string)myreader["name"],50); //limitation of my field
  date_inserted=myreader["date_inserted"];
  sqlInsert=string.Format("insert into table(name,name2,date_inserted)values '{0}', '{1}', {2})",name,name2,date_inserted); //here is the problem name2 "Use of unassigned local variable"
  ExecuteSQL(sqlInsert)
 }

As different companies database has different fields i can not set value to each variable and there is a big number of tables to go one variable to next.

like

sqlSelect_Company_1 = "select name,date_inserted from table_1";
sqlSelect_Company_2 = "select name,name2 from table_2";

is there a way to override the typing of each variable one by one with default values?

© Stack Overflow or respective owner

Related posts about c#

Related posts about database