Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Inserting Data into SQL Server DB but Database is still Empty

$
0
0

NEED HELP TO SOLVE

This is the method for collecting query

   private static void CreateStudent(StudentHandle ObjStudent)
        {
            String ConectionString = Properties.Settings.Default.Database1ConnectionString;
            String query="INSERT into STUDENT (RegNo,Batch,StudentName,Address,StudentPhone,DOB,Email,HomePage,"+
                "FatherName,FatherOffice,FatherCell,MotherName,MotherOffice,MotherCell,ResPhone,ResAddress,"+
                "AdmissionDate,AdmittedBy,PreviousInstituteName,PreviousInstituteAddress,PreviousInstituePhone,"+
                "PreviousInstituteLeaReason) Values ("+ObjStudent.RegNo+",'"+ObjStudent.Batch+"','"+ObjStudent.StudentName+"','"+ObjStudent.StudentAddress+
                "',"+ObjStudent.StudentPhone+",'"+ObjStudent.StudentDOB+"','"+ObjStudent.StudentEmail+"','"+ObjStudent.StudentHomePage+
                "','"+ObjStudent.FatherName+"',"+ObjStudent.FatherOffice+","+ObjStudent.FatherCell+",'"+ObjStudent.MotherName+
                "',"+ObjStudent.MotherOffice+","+ObjStudent.MotherCell+","+ObjStudent.ResidencePhone+",'"+ObjStudent.ResidenceAddress+
                "','"+ObjStudent.AdmissionDate+"','"+ObjStudent.AddmittedBy+"','"+ObjStudent.PreInsName+"','"+ObjStudent.PreInsAddress+
                "',"+ObjStudent.PreInsPhone+",'"+ObjStudent.PreInsLeareason+"')";
                QueryHandle.ExcuteNonQuery(ConectionString,query);
        }

// and this is Query Method

  public static void ExcuteNonQuery(String ConectionString, String Query)
        {
            SqlConnection myconection = new SqlConnection(ConectionString);
            try
            {

                myconection.Open();
                SqlCommand mycommand = new SqlCommand(Query,myconection);
                mycommand.ExecuteNonQuery();
               
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw ex;
               
            }
            finally
            {
                if (myconection.State == ConnectionState.Open)
                {
                    myconection.Close();
                }
            }
        }




Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>