משהו יכול לעזור לי אני עדין מסתבכת בשליפת נתונים מה DB

מ ו ת

New member
משהו יכול לעזור לי אני עדין מסתבכת בשליפת נתונים מה DB

כתבתי כך :
זה מתחבר לי לDB ולא שולף נתונים אני לא מצליחה לגשת לטבלה ... הדגשתי איפה מסומן לי בעיה באדום ...

DataContext dc = new DataContext("Data

Source=213.151.36.65,1433;Initial Catalog=;Persist Security Info=True;User ID=;Password=");
using (var dt = new DataClasses1DataContext("Data Source=213.151.36.65,1433;Initial Catalog=;Persist Security Info=True;User ID=;Password="))
{
//פה השגיאה var s1 = from Ocrd in dt.
select Math.Max(Ocrd.CardCode);
}
 

מ ו ת

New member
אני צריכה לעשות גם שאילתות שליפה פשוטות וגם עדכון ...

אני צריכה לעשות גם שאילתות שליפה פשוטות וגם עדכון ...
השאילתות של העדכון עובדות לי מצוין הם מתחברות למסד נתונים ומכניסות לתוכו נתונים בצורה טובה , הבעיה שאני לא יודעת מהי שהשאילתות של השליפה לא עובדות, תמיד זה שולף לי -1 :
&nbsp
string s2 = "select Id from Product ";
SqlCommand ss = new SqlCommand(s2, objConn);
ss.ExecuteNonQuery();
 

ht2006

New member
לא להשתמש ב - ExecuteNonQuery

השתמשי ב - FillAdapter
קוד:
public DataTable FillAdapter(string strProcName, Hashtable htParams)
        {
            SqlCommand sqlCommand = null;
            SqlDataAdapter sqlAdapter = null;
            try
            {
                DataTable dtDetails = new DataTable();
                sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.CommandText = strProcName;
                sqlCommand.Connection = sqlCon;
                if (htParams != null)
                {
                    foreach (string key in htParams.Keys)
                    {
                        sqlCommand.Parameters.Add(new SqlParameter(key, htParams[key]));
                    }
                }
                sqlAdapter = new SqlDataAdapter(sqlCommand);
                sqlAdapter.Fill(dtDetails);
                return dtDetails;
            }
            catch (Exception ex)
            {
                //Log.Error("MyDAL", "DAL", "FillAdapter", ex.Message);
                return null;
            }
            finally
            {
                if (sqlCommand != null)
                {
                    sqlCommand.Dispose();
                    sqlCommand = null;
                }
                if (sqlAdapter != null)
                {
                    sqlAdapter.Dispose();
                    sqlAdapter = null;
                }            
                if (sqlCon != null)
                {                
                    sqlCon.Close();
                    sqlCon.Dispose();
                    sqlCon = null;
                }
            }
        }
 
למעלה