完整字符串:string SqlIns = "insert into tb_abc (A1,A2,A3,A4,A5,A6,A7) values ('" + dataGridView1.Rows[i].Cells[0].Value + "','" + dataGridView1.Rows[i].Cells[1].Value + "','" + dataGridView1.Rows[i].Cells[2].Value + "','" + dataGridView1.Rows[i].Cells[3].Value + "','" + dataGridView1.Rows[i].Cells[4].Value + "','" + dataGridView1.Rows[i].Cells[5].Value + "','" + dataGridView1.Rows[i].Cells[6].Value + "')";
我按以下格式换行老是提示“常量中有换行符”,怎么回事呀。
string SqlIns = "insert into tb_abc (A1,A2,A3,A4,A5,A6,A7) values 
" ('" + dataGridView1.Rows[i].Cells[0].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[1].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[2].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[3].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[4].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[5].Value + "',"+
"'" + dataGridView1.Rows[i].Cells[6].Value + "')";

解决方案 »

  1.   

    string SqlIns = "insert into tb_abc (A1,A2,A3,A4,A5,A6,A7) values "+ 
    " ('" + dataGridView1.Rows[i].Cells[0].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[1].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[2].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[3].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[4].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[5].Value + "',"+
    "'" + dataGridView1.Rows[i].Cells[6].Value + "')";
      

  2.   

    自动换行:
    dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
      

  3.   

    vs菜单里工具->选项->文本编辑器->C#->自动换行
      

  4.   

    例如:string  temp = "this is a test";string temp = "this is"
                 +" a test";结果仍然是相同的
      

  5.   

    例如:string temp = "this is a test";string temp = "this is"
      +" a test";结果仍然是相同的
      

  6.   

    建议你最好用这种格式,以后看代码和调试都会方便很多
    string str="xxxxxx";
    str+=value1;
    str+=value2;
      

  7.   

    用+号连接字符串,
    或者你定义一个可变字符串,例如:
     StringBuilder strSql = new StringBuilder();
                strSql.Append("select ");
                strSql.Append(“name”);
                strSql.Append(" FROM ");
                strSql.Append(“table”);
      

  8.   

    sql语句中不能强行换行的,楼主不能那么写哦!
    楼主可以写一个追加字符串的程序,定义一个可变字符串,例如:
     StringBuilder strSql = new StringBuilder();
      strSql.Append("select ");
      strSql.Append(“name”);
      strSql.Append(" FROM ");
      strSql.Append(“table”);
    这样strsql的最终结果就是"select name from table";
      

  9.   

    使用StringBulider 的话是最好的,不用创建多个对象的,而且看起来比较清晰的
    StringBuilder sb= new StringBuilder();
    sb.Append("XXXX");
      

  10.   

    sb.AppendLine("XXXX");