|
|
|
รบกวนพี่ๆ ช่วยดูให้หน่อยครับ C# พอกดปุ่ม Insert แล้วมัน Error ดังรูปด้านในครับ |
|
|
|
|
|
|
|
Formนี้ คือ ลงทะเบียนเล็กๆ น่ะครับ
โดย สามารถ กรอก รหัสนักเรียน ชื่อ สกุล เพิ่มรูปภาพ คณะ วันเกิด เพศ
ปัญหาตอนนี้คือ พอกดปุ่ม Insert แล้วมันขึน incorrect syntax near
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using Jobgroup.Class;
namespace Jobgroup
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string constr;
SqlConnection connection;
SqlCommand command;
private void showdata()
{
try
{
//string conStr = "Data Source=192.168.1.13; Initial Catalog=Northwind;User ID=db01;Password=0866440068";
constr = DBConfig._constr;
connection = new SqlConnection(constr);
connection.Open();
MessageBox.Show("yes");
string sql = "SELECT * FROM regis";
command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet data = new DataSet();
adapter.Fill(data, "regis");
dataGridView1.DataSource = data.Tables["regis"];
connection.Close();
}
catch
{
MessageBox.Show("error");
}
}
private void Form1_Load(object sender, EventArgs e)
{
showdata();
comboBox1.Items.Add("Male");
comboBox1.Items.Add("Female");
}
private void btninsert_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
string sql = "INSERT INTO " + " regis (auto_id,id_std,name,lastname,pic,faculty,birth,sex); VALUES(@auto, @idstd,@name,@lastname,@pic,@facu,@birth,@sex);";
SqlCommand comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("id_std", textBox1.Text);
comm.Parameters.AddWithValue("name", textBox2.Text);
comm.Parameters.AddWithValue("lastname", textBox3.Text);
comm.Parameters.AddWithValue("faculty", textBox5.Text);
comm.Parameters.AddWithValue("birth", textBox6.Text);
FileStream fiStream = new FileStream(textBox4.Text, FileMode.Open, FileAccess.Read);
BinaryReader binReader = new BinaryReader(fiStream);
int fiLen = (int)fiStream.Length;
byte[] pic = binReader.ReadBytes(fiLen);
comm.Parameters.AddWithValue("pic", pic);
int afftectedRows = comm.ExecuteNonQuery();
if (afftectedRows == -1)
{
{
MessageBox.Show("เกิดข้อผิดพลาด " + Environment.NewLine + "ไม่สามารถแก้ไขข้อมูลได้");
}
conn.Close();
showdata();
}
}
private void btnbrowse_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image Files(*.gif;*.jpg)|*.gif;*.jpg";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox4.Text = openFileDialog1.FileName;
}
}
}
}
Tag : Ms SQL Server 2008, Web (ASP.NET), Win (Windows App), C, Windows
|
|
|
|
|
|
Date :
2015-03-22 15:14:08 |
By :
songpon pn |
View :
873 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|