Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

I INSERT DAta into SQL Daata Base using C# visual studio and succeeded but database not updated successfully, table still empty

$
0
0

this fucntion calls query method

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);
        }

// these are two methods for Query handling

 public static DataTable ExcuteQuery(String conStr, String query, String tableName)
        {
            try
            {

                SqlConnection MyConection = new SqlConnection(conStr);
                SqlDataAdapter Da = new SqlDataAdapter(query, MyConection);
                DataSet ds = new DataSet();
                Da.Fill(ds, tableName);
                ds.Tables[0].TableName = tableName;
                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw ex;
            }


        }
        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 23857

Trending Articles



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