>>namespace TypedDataSetTest >>{ >> class MyTest >> { >> static void Main(string[] args) >> { >> // Reference to this class >> MyTest oThis = new MyTest(); >> >> // Instance of the typed dataset >> DSAppUser oDSUser = null; >> >> // New record >> oDSUser = oThis.GetAppUser(-1); >> >> // Existing record >> oDSUser = oThis.GetAppUser(5); >> >> } >> >> public DSAppUser GetAppUser(int iUserKey) >> { >> // Instance of the typed dataset >> DSAppUser oDSUser = new DSAppUser(); >> >> // If no key was passed... >> if (iUserKey == -1) >> { >> // Add a new row >> oDSUser.Tables[0].Rows.Add(); >> } >> else >> { >> // Connect to the DB & get the requested record >> SqlConnection oConnection = new SqlConnection(sConnString); >> SqlCommand oCommand = new SqlCommand("select * from AppUsers where UserKey = " + iUserKey.ToString(), oConnection); >> SqlDataAdapter oAdapter = new SqlDataAdapter(oCommand); >> >> oAdapter.Fill(oDSUser, oDSUser.Tables[0].TableName); >> } >> >> return oDSUser; >> } >> } >>} >>