0

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)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by reach_yousuf
0

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')
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.