s_reg,s_don are two tables in my database reg_id is primary key of s_reg and don_id is of s_don
i have joined two tables using reg_id of both the tables
but in s_don table the reg_id column taking only zero and not showing the actual reg_id of s_reg
What I have tried:
protected void Button1_Click(object sender, EventArgs e)
{
using (studentDataContext dt = new studentDataContext())
{
var log = (from s in db.s_dons
join m in db.s_regs on s.reg_id equals m.reg_id
select new
{
s,m
}).FirstOrDefault();
try
{
s_reg reg = new s_reg();
s_don ureg = new s_don();
ureg.dtype = DropDownList2.SelectedItem.Text;
ureg.dtitle = DropDownList1.SelectedItem.Text;
ureg.dnmame = TextBox1.Text;
ureg.ddate = TextBox2.Text;
ureg.demail = TextBox5.Text;
ureg.dmob = TextBox6.Text;
ureg.dadd = TextBox7.Text;
ureg.ddepart = ddlTest.SelectedItem.Text;
ureg.damt = TextBox3.Text;
ureg.dcom = TextBox4.Text;
dt.s_dons.InsertOnSubmit(ureg);
dt.SubmitChanges();
var frps = dt.s_dons.Where(w => w.dnmame == TextBox1.Text);
foreach (var ti in frps)
{
ureg.reg_id = reg.reg_id;
dt.SubmitChanges();
}
}
catch (Exception ex)
{
Response.Write("Error:" + ex.Message);
}
}
}
s_reg:
CREATE TABLE [dbo].[s_reg](
[reg_id] [int] IDENTITY(2000,1) NOT NULL,
[pass_id] [int] NULL,
[sname] [nvarchar](50) NULL,
[smobile] [nvarchar](50) NULL,
[semail] [nvarchar](50) NULL,
[sdept] [nvarchar](50) NULL,
[scateg] [nvarchar](50) NULL,
[susnm] [nvarchar](50) NULL,
[spass] [nvarchar](50) NULL,
CONSTRAINT [PK_s_reg] PRIMARY KEY CLUSTERED
(
[reg_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
s_log:
CREATE TABLE [dbo].[s_log](
[log_id] [int] IDENTITY(1000,1) NOT NULL,
[reg_id] [int] NULL,
[susnm] [nvarchar](50) NULL,
[spass] [nvarchar](50) NULL,
CONSTRAINT [PK_s_log] PRIMARY KEY CLUSTERED
(
[log_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]