我正在使用 asp.net c# 和 Mysql 进行在线购物项目。我正在使用 Devart Linqconnect (LinqtoMysql)。我在 mysql 客户和客户地址中有两个表:
客户表
CustomerID Int
Customerhone varchar(20);
客户密码 Varchar(20);
电子邮件 varchar(20)
名字 char(50)姓氏(
50)
用户名 varshar(50)
Customer_Addresses
Customer_address_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Customer_ID INT NOT NULL,
address1 CHAR(250),
address2 CHAR(250),
city CHAR(20),
state CHAR(20), pincode VARCHAR(20),
PRIMARY KEY(Customer_address_ID),
FOREIGN KEY (Customer_ID) REFERENCES customers(Customer_ID)
当我在使用 LINQ to mysql 注册客户时编写此代码时:
using (ShoppingDataContext data = new ShoppingDataContext())
{
Customer NewCustomer = new Customer();
CustomerAddress newaddress = new CustomerAddress();
newaddress.CustomerID = NewCustomer.CustomerID;
NewCustomer.CustomerFirstname = TextBoxFirstName.Text;
NewCustomer.CustomerLastname = TextBoxLastname.Text;
NewCustomer.CustomerEmail = TextBoxEmail.Text;
NewCustomer.Username = TextBoxusername.Text;
NewCustomer.CustomerPassword = TextBoxPassword.Text;
newaddress.Address1 = TextBoxAddress1.Text;
newaddress.Address2 = TextBoxAddress2.Text;
newaddress.City = TextBoxCity.Text;
newaddress.State = TextBoxState.Text;
newaddress.Pincode = TextBoxPincode.Text;
System.Web.Security.Membership.CreateUser(TextBoxusername.Text, TextBoxPassword.Text);
data.Customers.InsertOnSubmit(NewCustomer);
PanelRegister.Visible = false;
ConfimPanel.Visible = true;
}
此代码是否可以将数据插入到两个表中。请帮忙。customer_address表是否能够根据customerId作为外键检测输入的客户地址是customer表的..
我正在使用 ajax 工具包的模态弹出面板并在面板中添加注册和登录表的另一件事..
我的注册面板:
提前致谢...