Dim datetimepicker1 As String = Format(System.DateTime.Now, "yyyy-MM-dd HH:mm:ss")
Try
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = "INSERT INTO tbl_product (`prod_name`,`prod_desc`, `cat_id`, `uom_id`,`uom_num`, `dept_id`, `brand_id`, `size_id`, `type_id`, `remarks`, `date`) values (@prod_name,@prod_desc,@cat_id,@uom_id,@uom_num,@dept_id,@brand_id,@size_id,@type_id,@remarks,@date)"
.Connection = SQLConnection
.CommandType = CommandType.Text
.Parameters.AddWithValue("@prod_name", TextBox1.Text)
.Parameters.AddWithValue("@prod_desc", TextBox2.Text)
.Parameters.AddWithValue("@cat_id", ComboBox1.Text)
.Parameters.AddWithValue("@uom_id", ComboBox2.Text)
.Parameters.AddWithValue("@uom_num", TextBox3.Text)
.Parameters.AddWithValue("@dept_id", ComboBox3.Text)
.Parameters.AddWithValue("@brand_id", ComboBox4.Text)
.Parameters.AddWithValue("@size_id", ComboBox5.Text)
.Parameters.AddWithValue("@type_id", ComboBox6.Text)
.Parameters.AddWithValue("@remarks", RichTextBox1.Text)
.Parameters.AddWithValue("@date", datetimepicker1)
.ExecuteNonQuery()
End With
MsgBox(" SIze Successfully added")
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
无法添加或更新子行外键约束失败这是我的错误
这是我的表结构* * ** * ** * **** *8
--
-- 表的表结构tbl_brand
如果不存在则创建表tbl_brand
(
brand_id
int(11) NOT NULL AUTO_INCREMENT,
brand_name
varchar(200) NOT NULL,
brand_desc
varchar(200) DEFAULT NULL, PRIMARY KEY ( brand_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;
--
-- 为表转储数据tbl_brand
插入tbl_brand
( brand_id
, brand_name
, brand_desc
) 值 (1, 'Nike ', 'Nike Air '), (2, 'Crocs ', 'Class A '), (3, 'SafeGuard ', 'SafeGuard ');
--
-- 表的表结构tbl_category
如果不存在则创建表tbl_category
(
cat_id
int(11) NOT NULL AUTO_INCREMENT,
cat_name
varchar(200) NOT NULL,
cat_desc
varchar(200) NOT NULL, PRIMARY KEY ( cat_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3;
--
-- 为表转储数据tbl_category
插入tbl_category
( cat_id
, cat_name
, cat_desc
) 值 (1, '沐浴皂', '沐浴皂'), (2, '洗涤剂', '洗涤剂');
--
-- 表的表结构tbl_dept
如果不存在则创建表tbl_dept
(
dept_id
int(11) NOT NULL AUTO_INCREMENT,
dept_name
varchar(200) NOT NULL,
dept_desc
varchar(200) NOT NULL, PRIMARY KEY ( dept_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3;
--
-- 为表转储数据tbl_dept
插入tbl_dept
( dept_id
, dept_name
, dept_desc
) 值 (1, '鞋', '鞋'), (2, '肥皂', '肥皂');
--
-- 表的表结构tbl_product
如果不存在则创建表tbl_product
(
prod_id
int(11) NOT NULL AUTO_INCREMENT,
prod_name
varchar(200) NOT NULL,
prod_desc
varchar(200) DEFAULT NULL,
cat_id
int(11) NOT NULL,
dept_id
int(11) NOT NULL,
brand_id
int(11) NOT NULL,
type_id
int (11) NOT NULL,
uom_id
int(11) NOT NULL,
size_id
int(11) NOT NULL,
date
datetime NOT NULL,
remarks
varchar(200) DEFAULT NULL,
uom_num
int(60) DEFAULT NULL, PRIMARY KEY ( prod_id
), KEY tbl_product_ibfk_9
( type_id
), KEY tbl_product_ibfk_10
( uom_id
) , 键tbl_product_ibfk_11
( size_id
), 键tbl_product_ibfk_12
( dept_id
), 键tbl_product_ibfk_13
( cat_id
), 键tbl_product_ibfk_14
( brand_id
) ); 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=3 ;
--
-- 表的表结构tbl_size
如果不存在则创建表tbl_size
(
size_id
int(11) NOT NULL AUTO_INCREMENT,
size_name
varchar(100) NOT NULL, PRIMARY KEY ( size_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;
--
-- 为表转储数据tbl_size
插入tbl_size
( size_id
, size_name
) 值 (1, 'Small(S) '), (2, 'Medium(M) '), (3, 'Large(L) ');
--
-- 表的表结构tbl_type
如果不存在则创建表tbl_type
(
type_id
int(11) NOT NULL AUTO_INCREMENT,
type_name
varchar(200) NOT NULL, PRIMARY KEY ( type_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9;
--
-- 为表转储数据tbl_type
INSERT INTO tbl_type
( type_id
, type_name
) VALUES (1, 'BaskertBall Shoes '), (2, 'Jersey Shorts '), (3, '跑鞋'), (8, 'Bath Soap ');
--
-- 表的表结构tbl_uom
如果不存在则创建表tbl_uom
(
uom_id
int(11) NOT NULL AUTO_INCREMENT,
uom_name
varchar(200) NOT NULL, PRIMARY KEY ( uom_id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8;
--
-- 为表转储数据tbl_uom
插入tbl_uom
( uom_id
, uom_name
) 值 (1, '公斤(kg) '), (2, '克(g) '), (3, '毫克(Mg) '), (4, '升(L) '), (5,'毫升(ml)'),(6,'件(pcs)'),(7,'英尺(ft)');
--
-- 表的表结构tbl_user
如果不存在则创建表tbl_user
(
user_id
int(11) NOT NULL AUTO_INCREMENT,
user_code
varchar(200) DEFAULT NULL,
user_password
varchar(200) DEFAULT NULL,
user_name
varchar(200) DEFAULT NULL,
user_level
int(1) DEFAULT NULL,
datetime
datetime NOT NULL,
com_code
varchar(11)非空,主键(user_id
),唯一键user_code
(user_code
))引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=10;
--
-- 为表转储数据tbl_user
插入tbl_user
( user_id
, user_code
, user_password
, user_name
, user_level
, datetime
, com_code
) 值 (1, '1024', '1024', 'Vincent Dematera', 3, '2012-01-10 18:18:33', '001'), (7, '14', '14', 'Megan Bueno', 1, '2012-10-30 21:56:14', '002'), (8, '13', '13', '匿名', 1, '2012-10-20 21:51:00', '002'), (9, '9', '9', 'boom', 1, '0000-00-00 00:00:00', '003 ');
--
-- 转储表的约束
--
-- 表格约束tbl_product
更改表tbl_product
添加约束外tbl_product_ibfk_9
键(type_id
)引用tbl_type
(type_id
),添加约束外tbl_product_ibfk_10
键(uom_id
)引用tbl_uom
(uom_id
),添加约束外tbl_product_ibfk_11
键(size_id
)引用tbl_size
(size_id
),添加约束外tbl_product_ibfk_12
键(dept_id
)引用tbl_dept
(dept_id
),添加约束外tbl_product_ibfk_13
键(cat_id
)引用tbl_category
(cat_id
),添加约束外tbl_product_ibfk_14
键(brand_id
)引用tbl_brand
(brand_id
),添加约束外tbl_product_ibfk_2
键(type_id
)引用tbl_type
(type_id
),添加约束外tbl_product_ibfk_3
键(uom_id
)引用tbl_uom
(uom_id
),添加约束tbl_product_ibfk_4
外键(size_id
)引用tbl_size
(size_id
),添加约束外tbl_product_ibfk_5
键(dept_id
)引用tbl_dept
(dept_id
),添加约束外tbl_product_ibfk_6
键(cat_id
)引用tbl_category
(cat_id
),添加约束外tbl_product_ibfk_7
键(brand_id
)引用tbl_brand
(brand_id
);设置 FOREIGN_KEY_CHECKS=1;