C sharp - No coinciden los tipos de datos en la expresión de criterios.

   
Vista:
Imágen de perfil de Guillermo

No coinciden los tipos de datos en la expresión de criterios.

Publicado por Guillermo (48 intervenciones) el 23/09/2015 02:13:15
Hola Gente, disculpen que los moleste, quiero consultarles,......debo llenar una Tabla AlumnoMateriasCurso, y tengo 3 GridsViews:}} uno de Alumno, donde selecciono datos del Alumno, uno de Curso, donde curso, y otro de Materias, pero con ChecksBoxs, donde puedo seleccionar una sola Materia, dos, etc....o todas.......y me da el Error del Titulo de este Post...........Creo haber dado con el codigo........si saben el problema, estoy agradecido si me pueden dar una mano.....saludos...

Este es el codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
protected void ButtonTodas_Click(object sender, EventArgs e)
        {
foreach
            (GridViewRow dgi in GridInscMaterias.Rows)
            {
                CheckBox myCheckBox = dgi.Cells[0].Controls[1] as CheckBox;
 
                if (myCheckBox != null)
                {
                    if (myCheckBox.Checked == true)
                    {
                        ViewState["idMateria"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria1"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria2"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria3"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria4"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria5"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria6"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria7"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria8"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
                        ViewState["idMateria9"] = GridInscMaterias.DataKeys[dgi.RowIndex][0].ToString();
 
                        {
                            string cadenaConexion = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                            OleDbConnection cnn = new OleDbConnection(cadenaConexion);
                            cnn.Open();
 
                            string SQL = string.Empty;
                            string SQL1 = string.Empty;
                            string SQL2 = string.Empty;
                            string SQL3 = string.Empty;
                            string SQL4 = string.Empty;
                            string SQL5 = string.Empty;
                            string SQL6 = string.Empty;
                            string SQL7 = string.Empty;
                            string SQL8 = string.Empty;
                            string SQL9 = string.Empty;
 
                            SQL = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria");
                            SQL1 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria1");
                            SQL2 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria2");
                            SQL3 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria3");
                            SQL4 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria4");
                            SQL5 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria5");
                            SQL6 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria6");
                            SQL7 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria7");
                            SQL8 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria8");
                            SQL9 = ("SELECT id_cursoMateria From CursosMaterias cm Where cm.id_Curso = @idCurso AND cm.id_Materia = @idMateria9");
 
                            ViewState["idCursoMateria"] = SQL;
                            ViewState["idCursoMateria1"] = SQL1;
                            ViewState["idCursoMateria2"] = SQL2;
                            ViewState["idCursoMateria3"] = SQL3;
                            ViewState["idCursoMateria4"] = SQL4;
                            ViewState["idCursoMateria5"] = SQL5;
                            ViewState["idCursoMateria6"] = SQL6;
                            ViewState["idCursoMateria7"] = SQL7;
                            ViewState["idCursoMateria8"] = SQL8;
                            ViewState["idCursoMateria9"] = SQL9;
 
                            string sql = string.Empty;
                            string sql1 = string.Empty;
                            string sql2 = string.Empty;
                            string sql3 = string.Empty;
                            string sql4 = string.Empty;
                            string sql5 = string.Empty;
                            string sql6 = string.Empty;
                            string sql7 = string.Empty;
                            string sql8 = string.Empty;
                            string sql9 = string.Empty;
 
                            sql = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat)";
                            sql1 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat1)";
                            sql2 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat2)";
                            sql3 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat3)";
                            sql4 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat4)";
                            sql5 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat5)";
                            sql6 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat6)";
                            sql7 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat7)";
                            sql8 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat8)";
                            sql9 = @"INSERT INTO AlumMatCursos (Id_Alumno, id_cursoMateria) VALUES (@idAlumno, @idcurMat9)";
 
                            OleDbCommand com = new OleDbCommand(SQL, cnn);
                            OleDbCommand com1 = new OleDbCommand(SQL1, cnn);
                            OleDbCommand com2 = new OleDbCommand(SQL2, cnn);
                            OleDbCommand com3 = new OleDbCommand(SQL3, cnn);
                            OleDbCommand com4 = new OleDbCommand(SQL4, cnn);
                            OleDbCommand com5 = new OleDbCommand(SQL5, cnn);
                            OleDbCommand com6 = new OleDbCommand(SQL6, cnn);
                            OleDbCommand com7 = new OleDbCommand(SQL7, cnn);
                            OleDbCommand com8 = new OleDbCommand(SQL8, cnn);
                            OleDbCommand com9 = new OleDbCommand(SQL9, cnn);
 
                            OleDbCommand cmd = new OleDbCommand(sql, cnn);
                            OleDbCommand cmd1 = new OleDbCommand(sql1, cnn);
                            OleDbCommand cmd2 = new OleDbCommand(sql2, cnn);
                            OleDbCommand cmd3 = new OleDbCommand(sql3, cnn);
                            OleDbCommand cmd4 = new OleDbCommand(sql4, cnn);
                            OleDbCommand cmd5 = new OleDbCommand(sql5, cnn);
                            OleDbCommand cmd6 = new OleDbCommand(sql6, cnn);
                            OleDbCommand cmd7 = new OleDbCommand(sql7, cnn);
                            OleDbCommand cmd8 = new OleDbCommand(sql8, cnn);
                            OleDbCommand cmd9 = new OleDbCommand(sql9, cnn);
 
                            com.Parameters.AddWithValue("@idCurso", (ViewState["idCurso"]));
 
                            com.Parameters.AddWithValue("@idMateria", (ViewState["idMateria"]));
                            com1.Parameters.AddWithValue("@idMateria1", (ViewState["idMateria1"]));
                            com2.Parameters.AddWithValue("@idMateria2", (ViewState["idMateria2"]));
                            com3.Parameters.AddWithValue("@idMateria3", (ViewState["idMateria3"]));
                            com4.Parameters.AddWithValue("@idMateria4", (ViewState["idMateria4"]));
                            com5.Parameters.AddWithValue("@idMateria5", (ViewState["idMateria5"]));
                            com6.Parameters.AddWithValue("@idMateria6", (ViewState["idMateria6"]));
                            com7.Parameters.AddWithValue("@idMateria7", (ViewState["idMateria7"]));
                            com8.Parameters.AddWithValue("@idMateria8", (ViewState["idMateria8"]));
                            com9.Parameters.AddWithValue("@idMateria9", (ViewState["idMateria9"]));
 
                            cmd.Parameters.AddWithValue("@idAlumno", (ViewState["idAlumno"]));
 
                            cmd.Parameters.AddWithValue("@idcurMat", (ViewState["idCursoMateria"]));
                            cmd1.Parameters.AddWithValue("@idcurMat1", (ViewState["idCursoMateria1"]));
                            cmd2.Parameters.AddWithValue("@idcurMat2", (ViewState["idCursoMateria2"]));
                            cmd3.Parameters.AddWithValue("@idcurMat3", (ViewState["idCursoMateria3"]));
                            cmd4.Parameters.AddWithValue("@idcurMat4", (ViewState["idCursoMateria4"]));
                            cmd5.Parameters.AddWithValue("@idcurMat5", (ViewState["idCursoMateria5"]));
                            cmd6.Parameters.AddWithValue("@idcurMat6", (ViewState["idCursoMateria6"]));
                            cmd7.Parameters.AddWithValue("@idcurMat7", (ViewState["idCursoMateria7"]));
                            cmd8.Parameters.AddWithValue("@idcurMat8", (ViewState["idCursoMateria8"]));
                            cmd9.Parameters.AddWithValue("@idcurMat9", (ViewState["idCursoMateria9"]));
 
                            com.ExecuteScalar();
 
                            cmd.ExecuteNonQuery();
                            cnn.Close();

El error ma salta en cmd.ExecuteNonQuery();

Abrazos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder