재우니의 블로그


아래는 sqlparameter 로 전송할 파라미터와 값을 할당하는 부분이다. addrange 함수를 통해 파라미터 배열값을 할당하여 전송이 가능하다. 여기서 파라미터 정의할때 데이터 형식이 기재되어 있지 않고 자동적으로 처리하도록 하였다. 대신 오라클일 경우에는 잘 인식하지 않은 부분이 있으니, 가급적 데이터 형식 및 길이를 명시적으로 해 주는것이 좋습니다.


string inQuery = @"insert into dbo.employee (person_id, name, lastname, street_nr, city, phone_fix, phone_mobile, email, salaire, dateentre, datesortie, lastchange, commentaire, foto) values(@peron_id, @nachname, @vorname, @streetnr, @city, @fix, @mobile, @email, @salaire, @entre, @sortie, @change, @comment, @image )"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@peron_id", (object)ckund.idUser), new SqlParameter("@nachname", (object)ckund.nName), new SqlParameter("@vorname", (object)ckund.vName), new SqlParameter("@streetnr", (object)ckund.StreetHausN), new SqlParameter("@city", (object)ckund.City), new SqlParameter("@fix", (object)ckund.Phonefix), new SqlParameter("@mobile", (object)ckund.Phonemobile), new SqlParameter("@email", (object)ckund.email), new SqlParameter("@salaire", (object)ckund.Salaire), new SqlParameter("@entre", (object)ckund.Entree), new SqlParameter("@sortie", (object)ckund.Sortie), new SqlParameter("@change", (object)ckund.LastChange), new SqlParameter("@comment", (object)ckund.Comment), new SqlParameter("@image", (object)ckund.Imgarr), };


SqlCommand myCommand = new SqlCommand(inQuery, conn.ConnectOpen()); myCommand.Parameters.AddRange(sqlParams); myCommand.CommandText = inQuery; myCommand.ExecuteNonQuery();