So my problem is :

student(STUDENT_ID,name,surname)
address(STUDENT_ID,city,number,state)
additional_info(STUDENT_ID,what,why,when)

IF STUDENT_ID IS IDENTITY , THEN THE PROBLEM IS EASILY SOLVED BY DECLARING A NEW VARIABLE WITH THE COMMAND SET SCOPE_IDENTITY , BUT IN MY CASE , ID_STUDENT IS FROM TYPE NVARCHAR, BECAUSE THE FORMAT OF THE ID SHOULD BE xxx/yyyy WHICH IS IMPOSIBLE TO MAKE IT IDENTITY

I'm inserting all the information trought textboxes and my code looks like this :

SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["MSConnectionString"].ConnectionString;
SqlCommand CmdSql = new SqlCommand("DECLARE @IND NVARCHAR(10);"+
"INSERT INTO STUDENT(ID_STUDENT,NAME,SURNAME)" +
"VALUES(@ID_STUDENT,@NAME,@SURNAME);"+
"INSERT INTO ADDRESS (ID_STUDENT,CITY,NUMBER,STATE)" +
"VALUES (@ID_STUDENT,@CITY,@NUMBER,@STATE)",conn);
conn.Open();

CmdSql.ExecuteNonQuery();
CmdSql.Parameters.Add(new SqlParameter("@ID_STUDENT", txtIndeks.Text));
CmdSql.Parameters.Add(new SqlParameter("@NAME", txtIme.Text));
CmdSql.Parameters.Add(new SqlParameter("@SURNAME", txtPrezime.Text));
CmdSql.Parameters.Add(new SqlParameter("@CITY", txtTatkovoIme.Text));
CmdSql.Parameters.Add(new SqlParameter("@NUMBER", txtEMBG.Text));

PLEASE CAN SOMEONE TELL ME HOW TO GET THE ID_STUDENT FROM THE TEXTBOX AND THAN INSERT IT INTO THESE 3 TABLES (IN STUDENT AS PK , AND IN ADRESS AND ADDIOTINAL_INFO AS FK AND ALSO PRIMARY)

So my problem is :

student(STUDENT_ID,name,surname)
address(STUDENT_ID,city,number,state)
additional_info(STUDENT_ID,what,why,when)

IF STUDENT_ID IS IDENTITY , THEN THE PROBLEM IS EASILY SOLVED BY DECLARING A NEW VARIABLE WITH THE COMMAND SET SCOPE_IDENTITY , BUT IN MY CASE , ID_STUDENT IS FROM TYPE NVARCHAR, BECAUSE THE FORMAT OF THE ID SHOULD BE xxx/yyyy WHICH IS IMPOSIBLE TO MAKE IT IDENTITY

I'm inserting all the information trought textboxes and my code looks like this :

SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["MSConnectionString"].ConnectionString;
SqlCommand CmdSql = new SqlCommand("DECLARE @IND NVARCHAR(10);"+
"INSERT INTO STUDENT(ID_STUDENT,NAME,SURNAME)" +
"VALUES(@ID_STUDENT,@NAME,@SURNAME);"+
"INSERT INTO ADDRESS (ID_STUDENT,CITY,NUMBER,STATE)" +
"VALUES (@ID_STUDENT,@CITY,@NUMBER,@STATE)",conn);
conn.Open();

CmdSql.ExecuteNonQuery();
CmdSql.Parameters.Add(new SqlParameter("@ID_STUDENT", txtIndeks.Text));
CmdSql.Parameters.Add(new SqlParameter("@NAME", txtIme.Text));
CmdSql.Parameters.Add(new SqlParameter("@SURNAME", txtPrezime.Text));
CmdSql.Parameters.Add(new SqlParameter("@CITY", txtTatkovoIme.Text));
CmdSql.Parameters.Add(new SqlParameter("@NUMBER", txtEMBG.Text));

PLEASE CAN SOMEONE TELL ME HOW TO GET THE ID_STUDENT FROM THE TEXTBOX AND THAN INSERT IT INTO THESE 3 TABLES (IN STUDENT AS PK , AND IN ADRESS AND ADDIOTINAL_INFO AS FK AND ALSO PRIMARY)

Hi
use the below statement if its a identity column

select  ident_current('tablename')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.