完整字符串: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 + "')";
我按以下格式换行老是提示“常量中有换行符”,怎么回事呀。
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 + "')";
" ('" + 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 + "')";
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
+" a test";结果仍然是相同的
+" a test";结果仍然是相同的
string str="xxxxxx";
str+=value1;
str+=value2;
或者你定义一个可变字符串,例如:
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.Append(“name”);
strSql.Append(" FROM ");
strSql.Append(“table”);
楼主可以写一个追加字符串的程序,定义一个可变字符串,例如:
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.Append(“name”);
strSql.Append(" FROM ");
strSql.Append(“table”);
这样strsql的最终结果就是"select name from table";
StringBuilder sb= new StringBuilder();
sb.Append("XXXX");