TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Enzo Enzo
NA
26
2.8k
Insert into multiple table PM and FkEy mysql database.
Jan 23 2017 11:33 AM
I want that value tblpetinfo.petid = tblpetowner.petid and tbladdress.address = tblpetowner.addressid
Can you add a condition for Terms List Box = lbTerm, CheckBox I Agree = chkTerm
Thank!!!
SOURCE CODE:::
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
using
MySql.Data.MySqlClient;
using
System.Configuration;
namespace
gpis
{
public
partial
class
registrationform : Form
{
public
registrationform()
{
InitializeComponent();
}
private
void
picHome_Click(
object
sender, EventArgs e)
{
menu frm =
new
menu();
frm.Show();
this
.Hide();
}
private
void
bRegister_Click(
object
sender, EventArgs e)
{
try
{
//This is my connection string i have assigned the database file address path
string
dbsource =
"datasource=localhost;port=3306;username=root;password=admin1234; database=db_gpis"
;
//This is MySqlConnection here i have created the object and pass my connection string
MySqlConnection MyConn1 =
new
MySqlConnection(dbsource);
//This is my insert query in which i am taking input from the user through windows forms
string
qpowner =
"insert into tblpetowner (polname,pofname,pomi,podob,pogen,pocontact,poemail,addressid) values(@ln,@fn,@mi,@dob,@gen,@cn,@em,addressid);"
;
//This is command class which will handle the vetinsert and myconn1 object.
MySqlCommand cmd1 =
new
MySqlCommand(qpowner, MyConn1);
cmd1.Parameters.AddWithValue(
"@ln"
, tLastname.Text);
cmd1.Parameters.AddWithValue(
"@fn"
, tFirstname.Text);
cmd1.Parameters.AddWithValue(
"@mi"
, tMiddleinitial.Text);
cmd1.Parameters.AddWithValue(
"@dob"
, tDob.Text);
cmd1.Parameters.AddWithValue(
"@gen"
, cmbGender.Text);
cmd1.Parameters.AddWithValue(
"@cn"
, tContactnum.Text);
cmd1.Parameters.AddWithValue(
"@em"
, tEmailadd.Text);
MySqlDataReader rdr1;
MyConn1.Open();
rdr1 = cmd1.ExecuteReader();
// Here our query will be executed and data saved into the database.
//while (rdr1.Read())
//{
//}
//MyConn1.Close();
//NEW CONNECTION
MySqlConnection addconn2 =
new
MySqlConnection(dbsource);
//This is my insert query in which i am taking input from the user through windows forms
string
qaddress =
"insert into tbladdress (addressid,hnum,street,brgy,city,region,country,zcode) values(@id,@hn,@st,@brgy,@cty,@re,@coun,@zc);"
;
//This is MySqlConnection here i have created the object and pass my connection string.
//This is command class which will handle the query and connection object.
MySqlCommand cmd2 =
new
MySqlCommand(qaddress, addconn2);
cmd2.Parameters.AddWithValue(
"@id"
,
null
);
cmd2.Parameters.AddWithValue(
"@hn"
, tHousenum.Text);
cmd2.Parameters.AddWithValue(
"@st"
, tStreet.Text);
cmd2.Parameters.AddWithValue(
"@brgy"
, tBrgy.Text);
cmd2.Parameters.AddWithValue(
"@cty"
, cmbCity.Text);
cmd2.Parameters.AddWithValue(
"@re"
, cmbRegion.Text);
cmd2.Parameters.AddWithValue(
"@coun"
, cmbCountry.Text);
cmd2.Parameters.AddWithValue(
"@zc"
, tZipcode.Text);
MySqlDataReader rdr2;
addconn2.Open();
rdr2 = cmd2.ExecuteReader();
//while (rdr2.Read())
//{
//}
//addconn2.Close();
//NEW CONNECTION
MySqlConnection addconn3 =
new
MySqlConnection(dbsource);
//This is my insert query in which i am taking input from the user through windows forms
string
qpet =
"insert into tblpetinfo (petid,petname, petcolor, petgen, ptype, pbreed) values(@id,@pn,@pc,@pg,@pt,@pb);"
;
//This is MySqlConnection here i have created the object and pass my connection string.
//This is command class which will handle the query and connection object.
MySqlCommand cmd3 =
new
MySqlCommand(qpet, addconn3);
cmd3.Parameters.AddWithValue(
"@id"
,
null
);
cmd3.Parameters.AddWithValue(
"@pn"
, tPetname.Text);
cmd3.Parameters.AddWithValue(
"@pc"
, tPetcolor.Text);
cmd3.Parameters.AddWithValue(
"@pg"
, cmbPetgender.Text);
cmd3.Parameters.AddWithValue(
"@pt"
, cmbType.Text);
cmd3.Parameters.AddWithValue(
"@pb"
, cmbBreed.Text);
MySqlDataReader rdr3;
addconn3.Open();
rdr3 = cmd3.ExecuteReader();
MessageBox.Show(
"Successful account registered"
);
menu menuForm =
new
menu();
menuForm.Show();
this
.Hide();
while
(rdr3.Read())
{
}
addconn3.Close();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Reply
Answers (
3
)
how to send free sms from windows form application in c#
Issue with Crystal report when not installed