Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert to database with field name TA/TJ with C#
    primarykey
    data
    text
    <p>Recently I've been assigned to a project where we have to migrate an old VB3 process to C#, this process takes data from an Access 97 file and Insert it into SQL Server, the problem is that some 'genius' call a field "Ta/Tj" and the '/' is breaking our code, we tried different ways but fail. We can't change the field name right now because we don't know exactly how many programs use that table. </p> <p>Here is my code </p> <pre><code> OleDbConnection connectionEpsOle = new OleDbConnection(); SqlConnection connectionEpsSql = (SqlConnection)GetConexion.GetConnectionIus(); DbDataAdapter dataAdapter; long nIus; long nIdGenealogia; string sRubroStr; DataSet dataSet = new DataSet(); DataRow dr; string sqlCadena = "SELECT * FROM Tesis WHERE ius =0"; dataAdapter = new SqlDataAdapter(); dataAdapter.SelectCommand = new SqlCommand(sqlCadena, connectionEpsSql); dataAdapter.Fill(dataSet, "Tesis"); sRubroStr = tesisDto.RUBRO; sRubroStr = MiscFunct.QuitaCarCad(sRubroStr); sRubroStr = MiscFunct.ConvMay(sRubroStr); sRubroStr = MiscFunct.QuitaDblEspacio(sRubroStr); sRubroStr = sRubroStr.Trim(); if (sRubroStr.Length &gt; 250) { sRubroStr = sRubroStr.Substring(0, 250); } dr = dataSet.Tables["Tesis"].NewRow(); dr["IUS"] = tesisDto.IUS; dr["Parte"] = 200; dr["Consec"] = 0; dr["Rubro"] = tesisDto.RUBRO; dr["Texto"] = tesisDto.TEXTO; dr["Prec"] = tesisDto.PRECEDENTES; dr["Epoca"] = tesisDto.Epoca; dr["Sala"] = tesisDto.Sala; dr["Fuente"] = tesisDto.Fuente; dr["Volumen"] = tesisDto.Volumen; dr["Tesis"] = tesisDto.Tesis; dr["Pagina"] = tesisDto.Pagina; dr["TA/TJ"] = tesisDto.TATJ; dr["Materia1"] = tesisDto.Materia1; dr["Materia2"] = tesisDto.Materia2; dr["Materia3"] = tesisDto.Materia3; dr["IdGenealogia"] = tesisDto.idGenealogia; dr["ConsecIndx"] = 0; dr["IdTCC"] = 0; dr["InfAnexos"] = 0; dr["LocAbr"] = " "; dr["NumLetra"] = 0; dr["ConsecLetra"] = 0; dr["Instancia"] = 0; dr["ConsecInst"] = 0; dr["LocExp"] = " "; dr["RIndx"] = "RRR"; dr["TIndx"] = "TTT"; dr["PIndx"] = "PPP"; dr["LIndx"] = "LLL"; dr["Certificada"] = 0; dr["IdSubVolumen"] = 0; dataSet.Tables["Tesis"].Rows.Add(dr); //dataAdapter.UpdateCommand = connectionEpsSQL.CreateCommand(); dataAdapter.InsertCommand = connectionEpsSql.CreateCommand(); dataAdapter.InsertCommand.CommandText = "INSERT INTO Tesis(IUS,Parte,Consec,Rubro,Texto,Prec," + "Epoca,Sala,Fuente,Volumen,Tesis,Pagina,[TA/TJ],Materia1,Materia2,Materia3," + "IdGenealogia,ConsecIndx,IdTCC,InfAnexos,LocAbr,NumLetra,ConsecLetra,Instancia," + "ConsecInst,LocExp,RIndx,TIndx,PIndx,LIndx,Certificada,IdSubVolumen)" + " VALUES(@IUS,@Parte,@Consec,@Rubro,@Texto,@Prec," + "@Epoca,@Sala,@Fuente,@Volumen,@Tesis,@Pagina,@[TA/TJ],@Materia1,@Materia2,@Materia3," + "@IdGenealogia,@ConsecIndx,@IdTCC,@InfAnexos,@LocAbr,@NumLetra,@ConsecLetra," + "@Instancia,@ ConsecInst,@LocExp,@RIndx,@TIndx,@PIndx," + "@LIndx,@Certificada,@IdSubVolumen)"; ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@IUS", SqlDbType.BigInt, 0, "IUS"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Parte", SqlDbType.Int, 0, "Parte"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Consec", SqlDbType.Int, 0, "Consec"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Rubro", SqlDbType.Text, 0, "Rubro"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Texto", SqlDbType.Text, 0, "Texto"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Prec", SqlDbType.Text, 0, "Prec"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Epoca", SqlDbType.Int, 0, "Epoca"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Sala", SqlDbType.Int, 0, "Sala"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Fuente", SqlDbType.Int, 0, "Fuente"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Volumen", SqlDbType.Int, 0, "Volumen"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Tesis", SqlDbType.VarChar, 0, "Tesis"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Pagina", SqlDbType.VarChar, 0, "Pagina"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@[TA/TJ]", SqlDbType.Int, 0, "TA/TJ"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Materia1", SqlDbType.Int, 0, "Materia1"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Materia2", SqlDbType.Int, 0, "Materia2"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Materia3", SqlDbType.Int, 0, "Materia3"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@IdGenealogia", SqlDbType.BigInt, 0, "IdGenealogia"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@ConsecIndx", SqlDbType.Int, 0, "ConsecIndx"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@idTCC", SqlDbType.SmallInt, 0, "idTCC"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@InfAnexos", SqlDbType.TinyInt, 0, "InfAnexos"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@LocAbr", SqlDbType.NVarChar, 0, "LocAbr"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@NumLetra", SqlDbType.TinyInt, 0, "NumLetra"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@ConsecLetra", SqlDbType.Int, 0, "ConsecLetra"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Instancia", SqlDbType.SmallInt, 0, "Instancia"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@ConsecInst", SqlDbType.Int, 0, "ConsecInst"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@LocExp", SqlDbType.NText, 0, "LocExp"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@RIndx", SqlDbType.NText, 0, "RIndx"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@TIndx", SqlDbType.NText, 0, "TIndx"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@PIndx", SqlDbType.NText, 0, "PIndx"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@LIndx", SqlDbType.NText, 0, "LIndx"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@Certificada", SqlDbType.TinyInt, 0, "Certificada"); ((SqlDataAdapter)dataAdapter).InsertCommand.Parameters.Add("@IdSubVolumen", SqlDbType.Int, 0, "IdSubVolumen"); dataAdapter.Update(dataSet, "Tesis"); dataSet.Dispose(); dataAdapter.Dispose(); connectionEpsOle.Close(); </code></pre> <p>The <code>Ta/Tj</code> column holds <code>tinyint</code> values</p> <p>Here is the SqlException message</p> <blockquote> <p><em>Line 1: Incorrect syntax near 'int'. Must declare the variable '@'.</em></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload