{"文字列データまたはバイナリ データが切り捨てられます。\r\nステートメントは終了されました。"}
このエラーの意味がわかりません。
生徒の情報登録画面で、
・姓 (MaxLength=6)
・名 (MaxLength=6)
・生年月日
・性別
・郵便番号
・住所 (MaxLength=20)
を入力できるTextBoxを用意しており、入力値は全てstring型の変数にしています。
```
string sei = textSei.Text;
string mei = textMei.Text;
string year = comboBox1.Text;
string month = comboBox2.Text;
string day = comboBox3.Text;
string seibetu = manBt.Checked ? "1" : "2";
string yuubin1 = textYuubin1.Text;
string yuubin2 = textYuubin2.Text;
string jyusyo = textJyusyo.Text;
//途中の条件は省略
//OKボタン押下時 if (result == DialogResult.OK) { //現在の日時を取得 DateTime dt = DateTime.Now; // 接続文字列の取得 var connectionString = ConfigurationManager.ConnectionStrings["sqlsvr"].ConnectionString; // データベース接続の準備 using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand()) { try { // データベースの接続開始 connection.Open(); // SQLの準備 command.CommandText = "INSERT INTO MEMBER_MASTER (name1, name2, birthday, gender, post_code, adress, date_created, last_updated) VALUES" + "(@name1, @name2, @birthday, @gender, @post_code, @adress, @date_created, @last_updated)"; command.Parameters.Add(new SqlParameter("@name1", sei)); //姓の登録 command.Parameters.Add(new SqlParameter("@name2", mei)); //名の登録 DateTime birthday; command.Parameters.Add(new SqlParameter("@birthday", DateTime.TryParse(year + "/" + month + "/" + day, out birthday) ? birthday : (object)DBNull.Value)); //生年月日の登録 command.Parameters.Add(new SqlParameter("@gender", seibetu)); //性別の登録 command.Parameters.Add(new SqlParameter("@post_code", yuubin1 == "" && yuubin2 == "" ? (object)DBNull.Value : yuubin1 + yuubin2)); //郵便番号の登録 command.Parameters.Add(new SqlParameter("@adress", jyusyo == "" ? (object)DBNull.Value : jyusyo)); //住所の登録 command.Parameters.Add(new SqlParameter("@date_created", dt)); //登録日付の登録 command.Parameters.Add(new SqlParameter("@last_updated", dt)); //更新日の登録 // SQLの実行 command.ExecuteNonQuery(); } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } finally { // データベースの接続終了 connection.Close(); }
全てのボックスに最大文字数入力して登録OKボタンをおすと上記のエラーが出てしまいました。 しかも、エラーが出るのは住所のTextBoxに20桁入れて登録ボタンを押した時です。 住所が空欄でそのほかのTextBoxは入力されている状態だとエラーは出ません。 住所の20桁で引っかかっているような気がします。 どうしてでしょうか。 :追記 入力情報 姓:ああああああ 名:いいいいいい 年:2000 月:2 日:2 性別:女性 郵便番号1:000 郵便番号2:0000 住所:あいうえおかきくけこさしすせそ12345
回答1件
あなたの回答
tips
プレビュー