CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: System Error

  1. #1
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    System Error

    Code:
    SqlConnection myConn = new SqlConnection();
    myConn.ConnectionString="Data Source=myIP,1433;Network Library=DBMSSOCN;Initial Catalog=gokhan;User ID=sa;Password=systems";
    		    myConn.Open();
    			try
    			{
    string StrSql = "INSERT into netonetable(netonename) VALUES myname";
    SqlCommand myCommand = new SqlCommand(StrSql, myConn);
    myCommand.ExecuteNonQuery();
    			}
    			finally
    			{
    		    myConn.Close();
    		                }
    well at this table i have lots of columns which are not allowed to be nulls.Can this error happen bc of just trying to insert A value and the others being null?
    Last edited by gokhan; September 12th, 2006 at 08:14 AM.

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: System Error

    If you have columns which do not allow Null values and you are not passing anything to those columns then this query will surely error out.

  3. #3
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    Re: System Error

    well i gave the values and it still gives the error.

    it is probably about connection.

    im trying to insert values to a database which is at another computer in the same room with myIP ip adress.sql server is running

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: System Error

    Does it error out at myConn.Open line?

    If so then the problem is with the connection string.

    Or if it errors out at the ExecuteNonQuery line then the problem is with the SQL Query.

  5. #5
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    Re: System Error

    string StrSql = "INSERT into netonetable VALUES (myname,myadress,myareacode,myphone,mykurumsal,myaramatik,myfatura,myvergi,mykimlik,mysicil,mysonay,myimza)";


    here is where it gives the error.

    AND

    mvergi mykimlik mysicil mysonay myimza are defined as intS in my C# code but in the database these are defined as bits.

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: System Error

    There is nothing wrong with the connection if it opens without any error. The problem is with your Query. If you want to add a row in the table then you should specify the column names too. And when you are trying to insert the values using the variables in your code then you need to put them like this
    Code:
    string SQL = "Insert Into TABLE1(NAME, ADDRESS, AGE) Values ('" + myName + "','" + myAddress + "'," + myAge.ToString() + ")";
    Where myName & myAddress are variables in the C# code defined as Strings and myAge is defined as Integer.

  7. #7
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    Re: System Error

    to be sure i have done all the things typed as string in c# and all the columns as varchar(50).

    it does not help.im sorry


    here is the code

    Code:
    			SqlConnection myConn = new SqlConnection();
    			myConn.ConnectionString="Data Source=myIP,1433;Network Library=DBMSSOCN;Initial Catalog=gokhan;User ID=sa;Password=";
    		    myConn.Open();
    			try
    			{
    				
    
    				
    				string StrSql = "Insert Into netonetable(name,adress,area,phone,kurumsal,aramatik,fatura,vergi,kimlik,sicil,sonay,imza)  VALUES (' " + myname + " ',' " + myadress + " ',' " + myareacode + "','" + myphone + " ', ' " +mykurumsal + " ', ' " + myaramatik + " ',' " + myfatura + " ',' " + myvergi + " ', ' " + mykimlik + " ',' " + mysicil + " ',' " + mysonay + " ', ' " +myimza + " ')";
    				SqlCommand myCommand = new SqlCommand(StrSql, myConn);
    				myCommand.ExecuteNonQuery();
    			}
    			finally
    			{
    		    myConn.Close();
    			}
    well all of them are stringS in code and varcharS(50) in the table

    does not help
    Last edited by gokhan; September 12th, 2006 at 09:48 AM.

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: System Error

    Can you show us the error message that it is showing?

  9. #9
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    Re: System Error

    it gives the System.Data.SqlClient.SqlException exception.
    Well thank you so much about the help.
    im gonna try to fix this problem bc im angry about it
    when i fix it and figure it out why it gives the error i will write down the error.

    What i see is just System.Data.SqlClient.SqlException and it writes out system error.the application gets frozen too

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: System Error

    That is kind of weird. Remove the Try block from your code and then try to execute it again, but execute it in the debug mode. If there is an error you will get atleast a little bit detailed message.

  11. #11
    Join Date
    Aug 2006
    Location
    izmir/Turkey
    Posts
    18

    Re: System Error

    i'll try this too.i hope this will help

    Thanks for help very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured