Connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kbipul
    New Member
    • Nov 2006
    • 27

    Connection

    Hi,

    I need to insert the entries of the log file into a database table..
    I have made a stored procedure but there is some problem .............I am unable to rectify that.........

    SqlConnection con=new SqlConnection(" Data Source=******** ***;Initial Catalog=WebServ icesLogFiles;Us er Id=sa;Password= sa;");
    con.Open();
    SqlCommand com=new SqlCommand("usp _addlogintotabl e",con);
    com.Parameters. Add(new SqlParameter("@ LogDateTime",Sq lDbType.DateTim e,0,"LogDateTim e"));
    com.Parameters. Add(new SqlParameter("@ MethodName",Sql DbType.VarChar, 50,"MethodName" ));
    com.Parameters. Add(new SqlParameter("@ Status",SqlDbTy pe.Int,0,"Statu s"));
    com.Parameters. Add(new SqlParameter("@ Message",SqlDbT ype.VarChar,100 ,"Message")) ;
    com.CommandType =CommandType.St oredProcedure;
    // com.Prepare();
    com.ExecuteNonQ uery();
    con.Close();
  • enreil
    New Member
    • Jan 2007
    • 86

    #2
    What sort of error do you get? Are you able to connect to your database at all, or is there an issue with your stored procedure?

    Comment

    • kbipul
      New Member
      • Nov 2006
      • 27

      #3
      Originally posted by enreil
      What sort of error do you get? Are you able to connect to your database at all, or is there an issue with your stored procedure?

      Hi, i am getting the error

      "Procedure 'usp_addloginto table' expects parameter '@LogDateTime', which was not supplied."

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Welcome to the pain of working with dates in databases. If you remove this field and test does it work? Look at your database field design and then test using format change. For uploading dates to db I find that datetime.parsee xact tends to work best. Here is an example that may help:
        How to convert user input in dMy format to Mdy?

        Comment

        • kbipul
          New Member
          • Nov 2006
          • 27

          #5
          Originally posted by kenobewan
          Welcome to the pain of working with dates in databases. If you remove this field and test does it work? Look at your database field design and then test using format change. For uploading dates to db I find that datetime.parsee xact tends to work best. Here is an example that may help:
          How to convert user input in dMy format to Mdy?

          Ya I tried after removing the datetime field.But still I could not get the desired result.The same problem continues for the other field after removing the datetime field..
          and the example that you sent to me is not very clear to me...May be I am not that well versed to get it.........

          Comment

          • kbipul
            New Member
            • Nov 2006
            • 27

            #6
            Originally posted by kbipul
            Ya I tried after removing the datetime field.But still I could not get the desired result.The same problem continues for the other field after removing the datetime field..
            and the example that you sent to me is not very clear to me...May be I am not that well versed to get it.........
            Hi,

            I have got the solution through a friend......... .........



            SqlParameter objpara = new SqlParameter();

            // For datetime

            objpara = new SqlParameter("@ LogDateTime",Sq lDbType.DateTim e);

            objpara.Value = DateTime.Now;

            com.Parameters. Add(objpara);



            this type of objects were required to locate the types of the entries

            Comment

            Working...